home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / hity wydania / Ubuntu 9.10 PL / karmelkowy-koliberek-9.10-netbook-remix-PL.iso / casper / filesystem.squashfs / usr / lib / python2.6 / lib-tk / Tkinter.pyc (.txt) < prev    next >
Python Compiled Bytecode  |  2009-11-11  |  199KB  |  4,830 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. '''Wrapper functions for Tcl/Tk.
  5.  
  6. Tkinter provides classes which allow the display, positioning and
  7. control of widgets. Toplevel widgets are Tk and Toplevel. Other
  8. widgets are Frame, Label, Entry, Text, Canvas, Button, Radiobutton,
  9. Checkbutton, Scale, Listbox, Scrollbar, OptionMenu, Spinbox
  10. LabelFrame and PanedWindow.
  11.  
  12. Properties of the widgets are specified with keyword arguments.
  13. Keyword arguments have the same name as the corresponding resource
  14. under Tk.
  15.  
  16. Widgets are positioned with one of the geometry managers Place, Pack
  17. or Grid. These managers can be called with methods place, pack, grid
  18. available in every Widget.
  19.  
  20. Actions are bound to events by resources (e.g. keyword argument
  21. command) or with the method bind.
  22.  
  23. Example (Hello, World):
  24. import Tkinter
  25. from Tkconstants import *
  26. tk = Tkinter.Tk()
  27. frame = Tkinter.Frame(tk, relief=RIDGE, borderwidth=2)
  28. frame.pack(fill=BOTH,expand=1)
  29. label = Tkinter.Label(frame, text="Hello, World")
  30. label.pack(fill=X, expand=1)
  31. button = Tkinter.Button(frame,text="Exit",command=tk.destroy)
  32. button.pack(side=BOTTOM)
  33. tk.mainloop()
  34. '''
  35. __version__ = '$Revision: 73770 $'
  36. import sys
  37. if sys.platform == 'win32':
  38.     import FixTk
  39.  
  40.  
  41. try:
  42.     import _tkinter
  43. except ImportError:
  44.     msg = None
  45.     raise ImportError, str(msg) + ', please install the python-tk package'
  46.  
  47. tkinter = _tkinter
  48. TclError = _tkinter.TclError
  49. from types import *
  50. from Tkconstants import *
  51. wantobjects = 1
  52. TkVersion = float(_tkinter.TK_VERSION)
  53. TclVersion = float(_tkinter.TCL_VERSION)
  54. READABLE = _tkinter.READABLE
  55. WRITABLE = _tkinter.WRITABLE
  56. EXCEPTION = _tkinter.EXCEPTION
  57.  
  58. try:
  59.     _tkinter.createfilehandler
  60. except AttributeError:
  61.     _tkinter.createfilehandler = None
  62.  
  63.  
  64. try:
  65.     _tkinter.deletefilehandler
  66. except AttributeError:
  67.     _tkinter.deletefilehandler = None
  68.  
  69.  
  70. def _flatten(tuple):
  71.     '''Internal function.'''
  72.     res = ()
  73.     for item in tuple:
  74.         if type(item) in (TupleType, ListType):
  75.             res = res + _flatten(item)
  76.             continue
  77.         if item is not None:
  78.             res = res + (item,)
  79.             continue
  80.     
  81.     return res
  82.  
  83.  
  84. try:
  85.     _flatten = _tkinter._flatten
  86. except AttributeError:
  87.     pass
  88.  
  89.  
  90. def _cnfmerge(cnfs):
  91.     '''Internal function.'''
  92.     if type(cnfs) is DictionaryType:
  93.         return cnfs
  94.     if type(cnfs) in (NoneType, StringType):
  95.         return cnfs
  96.     cnf = { }
  97.     for c in _flatten(cnfs):
  98.         
  99.         try:
  100.             cnf.update(c)
  101.         continue
  102.         except (AttributeError, TypeError):
  103.             type(cnfs) in (NoneType, StringType)
  104.             msg = type(cnfs) in (NoneType, StringType)
  105.             type(cnfs) is DictionaryType
  106.             print '_cnfmerge: fallback due to:', msg
  107.             for k, v in c.items():
  108.                 cnf[k] = v
  109.             
  110.         
  111.  
  112.     
  113.     return cnf
  114.  
  115.  
  116. try:
  117.     _cnfmerge = _tkinter._cnfmerge
  118. except AttributeError:
  119.     pass
  120.  
  121.  
  122. class Event:
  123.     '''Container for the properties of an event.
  124.  
  125.     Instances of this type are generated if one of the following events occurs:
  126.  
  127.     KeyPress, KeyRelease - for keyboard events
  128.     ButtonPress, ButtonRelease, Motion, Enter, Leave, MouseWheel - for mouse events
  129.     Visibility, Unmap, Map, Expose, FocusIn, FocusOut, Circulate,
  130.     Colormap, Gravity, Reparent, Property, Destroy, Activate,
  131.     Deactivate - for window events.
  132.  
  133.     If a callback function for one of these events is registered
  134.     using bind, bind_all, bind_class, or tag_bind, the callback is
  135.     called with an Event as first argument. It will have the
  136.     following attributes (in braces are the event types for which
  137.     the attribute is valid):
  138.  
  139.         serial - serial number of event
  140.     num - mouse button pressed (ButtonPress, ButtonRelease)
  141.     focus - whether the window has the focus (Enter, Leave)
  142.     height - height of the exposed window (Configure, Expose)
  143.     width - width of the exposed window (Configure, Expose)
  144.     keycode - keycode of the pressed key (KeyPress, KeyRelease)
  145.     state - state of the event as a number (ButtonPress, ButtonRelease,
  146.                             Enter, KeyPress, KeyRelease,
  147.                             Leave, Motion)
  148.     state - state as a string (Visibility)
  149.     time - when the event occurred
  150.     x - x-position of the mouse
  151.     y - y-position of the mouse
  152.     x_root - x-position of the mouse on the screen
  153.              (ButtonPress, ButtonRelease, KeyPress, KeyRelease, Motion)
  154.     y_root - y-position of the mouse on the screen
  155.              (ButtonPress, ButtonRelease, KeyPress, KeyRelease, Motion)
  156.     char - pressed character (KeyPress, KeyRelease)
  157.     send_event - see X/Windows documentation
  158.     keysym - keysym of the event as a string (KeyPress, KeyRelease)
  159.     keysym_num - keysym of the event as a number (KeyPress, KeyRelease)
  160.     type - type of the event as a number
  161.     widget - widget in which the event occurred
  162.     delta - delta of wheel movement (MouseWheel)
  163.     '''
  164.     pass
  165.  
  166. _support_default_root = 1
  167. _default_root = None
  168.  
  169. def NoDefaultRoot():
  170.     '''Inhibit setting of default root window.
  171.  
  172.     Call this function to inhibit that the first instance of
  173.     Tk is used for windows without an explicit parent window.
  174.     '''
  175.     global _support_default_root, _default_root
  176.     _support_default_root = 0
  177.     _default_root = None
  178.     del _default_root
  179.  
  180.  
  181. def _tkerror(err):
  182.     '''Internal function.'''
  183.     pass
  184.  
  185.  
  186. def _exit(code = '0'):
  187.     '''Internal function. Calling it will throw the exception SystemExit.'''
  188.     raise SystemExit, code
  189.  
  190. _varnum = 0
  191.  
  192. class Variable:
  193.     '''Class to define value holders for e.g. buttons.
  194.  
  195.     Subclasses StringVar, IntVar, DoubleVar, BooleanVar are specializations
  196.     that constrain the type of the value returned from get().'''
  197.     _default = ''
  198.     
  199.     def __init__(self, master = None, value = None, name = None):
  200.         '''Construct a variable
  201.  
  202.         MASTER can be given as master widget.
  203.         VALUE is an optional value (defaults to "")
  204.         NAME is an optional Tcl name (defaults to PY_VARnum).
  205.  
  206.         If NAME matches an existing variable and VALUE is omitted
  207.         then the existing value is retained.
  208.         '''
  209.         global _varnum
  210.         if not master:
  211.             master = _default_root
  212.         
  213.         self._master = master
  214.         self._tk = master.tk
  215.         if name:
  216.             self._name = name
  217.         else:
  218.             self._name = 'PY_VAR' + repr(_varnum)
  219.             _varnum += 1
  220.         if value is not None:
  221.             self.set(value)
  222.         elif not self._tk.call('info', 'exists', self._name):
  223.             self.set(self._default)
  224.         
  225.  
  226.     
  227.     def __del__(self):
  228.         '''Unset the variable in Tcl.'''
  229.         self._tk.globalunsetvar(self._name)
  230.  
  231.     
  232.     def __str__(self):
  233.         '''Return the name of the variable in Tcl.'''
  234.         return self._name
  235.  
  236.     
  237.     def set(self, value):
  238.         '''Set the variable to VALUE.'''
  239.         return self._tk.globalsetvar(self._name, value)
  240.  
  241.     
  242.     def get(self):
  243.         '''Return value of variable.'''
  244.         return self._tk.globalgetvar(self._name)
  245.  
  246.     
  247.     def trace_variable(self, mode, callback):
  248.         '''Define a trace callback for the variable.
  249.  
  250.         MODE is one of "r", "w", "u" for read, write, undefine.
  251.         CALLBACK must be a function which is called when
  252.         the variable is read, written or undefined.
  253.  
  254.         Return the name of the callback.
  255.         '''
  256.         cbname = self._master._register(callback)
  257.         self._tk.call('trace', 'variable', self._name, mode, cbname)
  258.         return cbname
  259.  
  260.     trace = trace_variable
  261.     
  262.     def trace_vdelete(self, mode, cbname):
  263.         '''Delete the trace callback for a variable.
  264.  
  265.         MODE is one of "r", "w", "u" for read, write, undefine.
  266.         CBNAME is the name of the callback returned from trace_variable or trace.
  267.         '''
  268.         self._tk.call('trace', 'vdelete', self._name, mode, cbname)
  269.         self._master.deletecommand(cbname)
  270.  
  271.     
  272.     def trace_vinfo(self):
  273.         '''Return all trace callback information.'''
  274.         return map(self._tk.split, self._tk.splitlist(self._tk.call('trace', 'vinfo', self._name)))
  275.  
  276.     
  277.     def __eq__(self, other):
  278.         """Comparison for equality (==).
  279.  
  280.         Note: if the Variable's master matters to behavior
  281.         also compare self._master == other._master
  282.         """
  283.         if self.__class__.__name__ == other.__class__.__name__:
  284.             pass
  285.         return self._name == other._name
  286.  
  287.  
  288.  
  289. class StringVar(Variable):
  290.     '''Value holder for strings variables.'''
  291.     _default = ''
  292.     
  293.     def __init__(self, master = None, value = None, name = None):
  294.         '''Construct a string variable.
  295.  
  296.         MASTER can be given as master widget.
  297.         VALUE is an optional value (defaults to "")
  298.         NAME is an optional Tcl name (defaults to PY_VARnum).
  299.  
  300.         If NAME matches an existing variable and VALUE is omitted
  301.         then the existing value is retained.
  302.         '''
  303.         Variable.__init__(self, master, value, name)
  304.  
  305.     
  306.     def get(self):
  307.         '''Return value of variable as string.'''
  308.         value = self._tk.globalgetvar(self._name)
  309.         if isinstance(value, basestring):
  310.             return value
  311.         return str(value)
  312.  
  313.  
  314.  
  315. class IntVar(Variable):
  316.     '''Value holder for integer variables.'''
  317.     _default = 0
  318.     
  319.     def __init__(self, master = None, value = None, name = None):
  320.         '''Construct an integer variable.
  321.  
  322.         MASTER can be given as master widget.
  323.         VALUE is an optional value (defaults to 0)
  324.         NAME is an optional Tcl name (defaults to PY_VARnum).
  325.  
  326.         If NAME matches an existing variable and VALUE is omitted
  327.         then the existing value is retained.
  328.         '''
  329.         Variable.__init__(self, master, value, name)
  330.  
  331.     
  332.     def set(self, value):
  333.         '''Set the variable to value, converting booleans to integers.'''
  334.         if isinstance(value, bool):
  335.             value = int(value)
  336.         
  337.         return Variable.set(self, value)
  338.  
  339.     
  340.     def get(self):
  341.         '''Return the value of the variable as an integer.'''
  342.         return getint(self._tk.globalgetvar(self._name))
  343.  
  344.  
  345.  
  346. class DoubleVar(Variable):
  347.     '''Value holder for float variables.'''
  348.     _default = 0
  349.     
  350.     def __init__(self, master = None, value = None, name = None):
  351.         '''Construct a float variable.
  352.  
  353.         MASTER can be given as master widget.
  354.         VALUE is an optional value (defaults to 0.0)
  355.         NAME is an optional Tcl name (defaults to PY_VARnum).
  356.  
  357.         If NAME matches an existing variable and VALUE is omitted
  358.         then the existing value is retained.
  359.         '''
  360.         Variable.__init__(self, master, value, name)
  361.  
  362.     
  363.     def get(self):
  364.         '''Return the value of the variable as a float.'''
  365.         return getdouble(self._tk.globalgetvar(self._name))
  366.  
  367.  
  368.  
  369. class BooleanVar(Variable):
  370.     '''Value holder for boolean variables.'''
  371.     _default = False
  372.     
  373.     def __init__(self, master = None, value = None, name = None):
  374.         '''Construct a boolean variable.
  375.  
  376.         MASTER can be given as master widget.
  377.         VALUE is an optional value (defaults to False)
  378.         NAME is an optional Tcl name (defaults to PY_VARnum).
  379.  
  380.         If NAME matches an existing variable and VALUE is omitted
  381.         then the existing value is retained.
  382.         '''
  383.         Variable.__init__(self, master, value, name)
  384.  
  385.     
  386.     def get(self):
  387.         '''Return the value of the variable as a bool.'''
  388.         return self._tk.getboolean(self._tk.globalgetvar(self._name))
  389.  
  390.  
  391.  
  392. def mainloop(n = 0):
  393.     '''Run the main loop of Tcl.'''
  394.     _default_root.tk.mainloop(n)
  395.  
  396. getint = int
  397. getdouble = float
  398.  
  399. def getboolean(s):
  400.     '''Convert true and false to integer values 1 and 0.'''
  401.     return _default_root.tk.getboolean(s)
  402.  
  403.  
  404. class Misc:
  405.     '''Internal class.
  406.  
  407.     Base class which defines methods common for interior widgets.'''
  408.     _tclCommands = None
  409.     
  410.     def destroy(self):
  411.         '''Internal function.
  412.  
  413.         Delete all Tcl commands created for
  414.         this widget in the Tcl interpreter.'''
  415.         if self._tclCommands is not None:
  416.             for name in self._tclCommands:
  417.                 self.tk.deletecommand(name)
  418.             
  419.             self._tclCommands = None
  420.         
  421.  
  422.     
  423.     def deletecommand(self, name):
  424.         '''Internal function.
  425.  
  426.         Delete the Tcl command provided in NAME.'''
  427.         self.tk.deletecommand(name)
  428.         
  429.         try:
  430.             self._tclCommands.remove(name)
  431.         except ValueError:
  432.             pass
  433.  
  434.  
  435.     
  436.     def tk_strictMotif(self, boolean = None):
  437.         '''Set Tcl internal variable, whether the look and feel
  438.         should adhere to Motif.
  439.  
  440.         A parameter of 1 means adhere to Motif (e.g. no color
  441.         change if mouse passes over slider).
  442.         Returns the set value.'''
  443.         return self.tk.getboolean(self.tk.call('set', 'tk_strictMotif', boolean))
  444.  
  445.     
  446.     def tk_bisque(self):
  447.         '''Change the color scheme to light brown as used in Tk 3.6 and before.'''
  448.         self.tk.call('tk_bisque')
  449.  
  450.     
  451.     def tk_setPalette(self, *args, **kw):
  452.         '''Set a new color scheme for all widget elements.
  453.  
  454.         A single color as argument will cause that all colors of Tk
  455.         widget elements are derived from this.
  456.         Alternatively several keyword parameters and its associated
  457.         colors can be given. The following keywords are valid:
  458.         activeBackground, foreground, selectColor,
  459.         activeForeground, highlightBackground, selectBackground,
  460.         background, highlightColor, selectForeground,
  461.         disabledForeground, insertBackground, troughColor.'''
  462.         self.tk.call(('tk_setPalette',) + _flatten(args) + _flatten(kw.items()))
  463.  
  464.     
  465.     def tk_menuBar(self, *args):
  466.         '''Do not use. Needed in Tk 3.6 and earlier.'''
  467.         pass
  468.  
  469.     
  470.     def wait_variable(self, name = 'PY_VAR'):
  471.         '''Wait until the variable is modified.
  472.  
  473.         A parameter of type IntVar, StringVar, DoubleVar or
  474.         BooleanVar must be given.'''
  475.         self.tk.call('tkwait', 'variable', name)
  476.  
  477.     waitvar = wait_variable
  478.     
  479.     def wait_window(self, window = None):
  480.         '''Wait until a WIDGET is destroyed.
  481.  
  482.         If no parameter is given self is used.'''
  483.         if window is None:
  484.             window = self
  485.         
  486.         self.tk.call('tkwait', 'window', window._w)
  487.  
  488.     
  489.     def wait_visibility(self, window = None):
  490.         '''Wait until the visibility of a WIDGET changes
  491.         (e.g. it appears).
  492.  
  493.         If no parameter is given self is used.'''
  494.         if window is None:
  495.             window = self
  496.         
  497.         self.tk.call('tkwait', 'visibility', window._w)
  498.  
  499.     
  500.     def setvar(self, name = 'PY_VAR', value = '1'):
  501.         '''Set Tcl variable NAME to VALUE.'''
  502.         self.tk.setvar(name, value)
  503.  
  504.     
  505.     def getvar(self, name = 'PY_VAR'):
  506.         '''Return value of Tcl variable NAME.'''
  507.         return self.tk.getvar(name)
  508.  
  509.     getint = int
  510.     getdouble = float
  511.     
  512.     def getboolean(self, s):
  513.         '''Return a boolean value for Tcl boolean values true and false given as parameter.'''
  514.         return self.tk.getboolean(s)
  515.  
  516.     
  517.     def focus_set(self):
  518.         '''Direct input focus to this widget.
  519.  
  520.         If the application currently does not have the focus
  521.         this widget will get the focus if the application gets
  522.         the focus through the window manager.'''
  523.         self.tk.call('focus', self._w)
  524.  
  525.     focus = focus_set
  526.     
  527.     def focus_force(self):
  528.         '''Direct input focus to this widget even if the
  529.         application does not have the focus. Use with
  530.         caution!'''
  531.         self.tk.call('focus', '-force', self._w)
  532.  
  533.     
  534.     def focus_get(self):
  535.         '''Return the widget which has currently the focus in the
  536.         application.
  537.  
  538.         Use focus_displayof to allow working with several
  539.         displays. Return None if application does not have
  540.         the focus.'''
  541.         name = self.tk.call('focus')
  542.         if name == 'none' or not name:
  543.             return None
  544.         return self._nametowidget(name)
  545.  
  546.     
  547.     def focus_displayof(self):
  548.         '''Return the widget which has currently the focus on the
  549.         display where this widget is located.
  550.  
  551.         Return None if the application does not have the focus.'''
  552.         name = self.tk.call('focus', '-displayof', self._w)
  553.         if name == 'none' or not name:
  554.             return None
  555.         return self._nametowidget(name)
  556.  
  557.     
  558.     def focus_lastfor(self):
  559.         '''Return the widget which would have the focus if top level
  560.         for this widget gets the focus from the window manager.'''
  561.         name = self.tk.call('focus', '-lastfor', self._w)
  562.         if name == 'none' or not name:
  563.             return None
  564.         return self._nametowidget(name)
  565.  
  566.     
  567.     def tk_focusFollowsMouse(self):
  568.         '''The widget under mouse will get automatically focus. Can not
  569.         be disabled easily.'''
  570.         self.tk.call('tk_focusFollowsMouse')
  571.  
  572.     
  573.     def tk_focusNext(self):
  574.         '''Return the next widget in the focus order which follows
  575.         widget which has currently the focus.
  576.  
  577.         The focus order first goes to the next child, then to
  578.         the children of the child recursively and then to the
  579.         next sibling which is higher in the stacking order.  A
  580.         widget is omitted if it has the takefocus resource set
  581.         to 0.'''
  582.         name = self.tk.call('tk_focusNext', self._w)
  583.         if not name:
  584.             return None
  585.         return self._nametowidget(name)
  586.  
  587.     
  588.     def tk_focusPrev(self):
  589.         '''Return previous widget in the focus order. See tk_focusNext for details.'''
  590.         name = self.tk.call('tk_focusPrev', self._w)
  591.         if not name:
  592.             return None
  593.         return self._nametowidget(name)
  594.  
  595.     
  596.     def after(self, ms, func = None, *args):
  597.         '''Call function once after given time.
  598.  
  599.         MS specifies the time in milliseconds. FUNC gives the
  600.         function which shall be called. Additional parameters
  601.         are given as parameters to the function call.  Return
  602.         identifier to cancel scheduling with after_cancel.'''
  603.         if not func:
  604.             self.tk.call('after', ms)
  605.         else:
  606.             
  607.             def callit():
  608.                 
  609.                 try:
  610.                     func(*args)
  611.                 finally:
  612.                     
  613.                     try:
  614.                         self.deletecommand(name)
  615.                     except TclError:
  616.                         pass
  617.  
  618.  
  619.  
  620.             name = self._register(callit)
  621.             return self.tk.call('after', ms, name)
  622.         return func
  623.  
  624.     
  625.     def after_idle(self, func, *args):
  626.         '''Call FUNC once if the Tcl main loop has no event to
  627.         process.
  628.  
  629.         Return an identifier to cancel the scheduling with
  630.         after_cancel.'''
  631.         return self.after('idle', func, *args)
  632.  
  633.     
  634.     def after_cancel(self, id):
  635.         '''Cancel scheduling of function identified with ID.
  636.  
  637.         Identifier returned by after or after_idle must be
  638.         given as first parameter.'''
  639.         
  640.         try:
  641.             data = self.tk.call('after', 'info', id)
  642.             script = self.tk.splitlist(data)[0]
  643.             self.deletecommand(script)
  644.         except TclError:
  645.             pass
  646.  
  647.         self.tk.call('after', 'cancel', id)
  648.  
  649.     
  650.     def bell(self, displayof = 0):
  651.         """Ring a display's bell."""
  652.         self.tk.call(('bell',) + self._displayof(displayof))
  653.  
  654.     
  655.     def clipboard_get(self, **kw):
  656.         """Retrieve data from the clipboard on window's display.
  657.  
  658.         The window keyword defaults to the root window of the Tkinter
  659.         application.
  660.  
  661.         The type keyword specifies the form in which the data is
  662.         to be returned and should be an atom name such as STRING
  663.         or FILE_NAME.  Type defaults to STRING.
  664.  
  665.         This command is equivalent to:
  666.  
  667.         selection_get(CLIPBOARD)
  668.         """
  669.         return self.tk.call(('clipboard', 'get') + self._options(kw))
  670.  
  671.     
  672.     def clipboard_clear(self, **kw):
  673.         '''Clear the data in the Tk clipboard.
  674.  
  675.         A widget specified for the optional displayof keyword
  676.         argument specifies the target display.'''
  677.         if not kw.has_key('displayof'):
  678.             kw['displayof'] = self._w
  679.         
  680.         self.tk.call(('clipboard', 'clear') + self._options(kw))
  681.  
  682.     
  683.     def clipboard_append(self, string, **kw):
  684.         '''Append STRING to the Tk clipboard.
  685.  
  686.         A widget specified at the optional displayof keyword
  687.         argument specifies the target display. The clipboard
  688.         can be retrieved with selection_get.'''
  689.         if not kw.has_key('displayof'):
  690.             kw['displayof'] = self._w
  691.         
  692.         self.tk.call(('clipboard', 'append') + self._options(kw) + ('--', string))
  693.  
  694.     
  695.     def grab_current(self):
  696.         '''Return widget which has currently the grab in this application
  697.         or None.'''
  698.         name = self.tk.call('grab', 'current', self._w)
  699.         if not name:
  700.             return None
  701.         return self._nametowidget(name)
  702.  
  703.     
  704.     def grab_release(self):
  705.         '''Release grab for this widget if currently set.'''
  706.         self.tk.call('grab', 'release', self._w)
  707.  
  708.     
  709.     def grab_set(self):
  710.         '''Set grab for this widget.
  711.  
  712.         A grab directs all events to this and descendant
  713.         widgets in the application.'''
  714.         self.tk.call('grab', 'set', self._w)
  715.  
  716.     
  717.     def grab_set_global(self):
  718.         '''Set global grab for this widget.
  719.  
  720.         A global grab directs all events to this and
  721.         descendant widgets on the display. Use with caution -
  722.         other applications do not get events anymore.'''
  723.         self.tk.call('grab', 'set', '-global', self._w)
  724.  
  725.     
  726.     def grab_status(self):
  727.         '''Return None, "local" or "global" if this widget has
  728.         no, a local or a global grab.'''
  729.         status = self.tk.call('grab', 'status', self._w)
  730.         if status == 'none':
  731.             status = None
  732.         
  733.         return status
  734.  
  735.     
  736.     def option_add(self, pattern, value, priority = None):
  737.         '''Set a VALUE (second parameter) for an option
  738.         PATTERN (first parameter).
  739.  
  740.         An optional third parameter gives the numeric priority
  741.         (defaults to 80).'''
  742.         self.tk.call('option', 'add', pattern, value, priority)
  743.  
  744.     
  745.     def option_clear(self):
  746.         '''Clear the option database.
  747.  
  748.         It will be reloaded if option_add is called.'''
  749.         self.tk.call('option', 'clear')
  750.  
  751.     
  752.     def option_get(self, name, className):
  753.         '''Return the value for an option NAME for this widget
  754.         with CLASSNAME.
  755.  
  756.         Values with higher priority override lower values.'''
  757.         return self.tk.call('option', 'get', self._w, name, className)
  758.  
  759.     
  760.     def option_readfile(self, fileName, priority = None):
  761.         '''Read file FILENAME into the option database.
  762.  
  763.         An optional second parameter gives the numeric
  764.         priority.'''
  765.         self.tk.call('option', 'readfile', fileName, priority)
  766.  
  767.     
  768.     def selection_clear(self, **kw):
  769.         '''Clear the current X selection.'''
  770.         if not kw.has_key('displayof'):
  771.             kw['displayof'] = self._w
  772.         
  773.         self.tk.call(('selection', 'clear') + self._options(kw))
  774.  
  775.     
  776.     def selection_get(self, **kw):
  777.         '''Return the contents of the current X selection.
  778.  
  779.         A keyword parameter selection specifies the name of
  780.         the selection and defaults to PRIMARY.  A keyword
  781.         parameter displayof specifies a widget on the display
  782.         to use.'''
  783.         if not kw.has_key('displayof'):
  784.             kw['displayof'] = self._w
  785.         
  786.         return self.tk.call(('selection', 'get') + self._options(kw))
  787.  
  788.     
  789.     def selection_handle(self, command, **kw):
  790.         '''Specify a function COMMAND to call if the X
  791.         selection owned by this widget is queried by another
  792.         application.
  793.  
  794.         This function must return the contents of the
  795.         selection. The function will be called with the
  796.         arguments OFFSET and LENGTH which allows the chunking
  797.         of very long selections. The following keyword
  798.         parameters can be provided:
  799.         selection - name of the selection (default PRIMARY),
  800.         type - type of the selection (e.g. STRING, FILE_NAME).'''
  801.         name = self._register(command)
  802.         self.tk.call(('selection', 'handle') + self._options(kw) + (self._w, name))
  803.  
  804.     
  805.     def selection_own(self, **kw):
  806.         '''Become owner of X selection.
  807.  
  808.         A keyword parameter selection specifies the name of
  809.         the selection (default PRIMARY).'''
  810.         self.tk.call(('selection', 'own') + self._options(kw) + (self._w,))
  811.  
  812.     
  813.     def selection_own_get(self, **kw):
  814.         '''Return owner of X selection.
  815.  
  816.         The following keyword parameter can
  817.         be provided:
  818.         selection - name of the selection (default PRIMARY),
  819.         type - type of the selection (e.g. STRING, FILE_NAME).'''
  820.         if not kw.has_key('displayof'):
  821.             kw['displayof'] = self._w
  822.         
  823.         name = self.tk.call(('selection', 'own') + self._options(kw))
  824.         if not name:
  825.             return None
  826.         return self._nametowidget(name)
  827.  
  828.     
  829.     def send(self, interp, cmd, *args):
  830.         '''Send Tcl command CMD to different interpreter INTERP to be executed.'''
  831.         return self.tk.call(('send', interp, cmd) + args)
  832.  
  833.     
  834.     def lower(self, belowThis = None):
  835.         '''Lower this widget in the stacking order.'''
  836.         self.tk.call('lower', self._w, belowThis)
  837.  
  838.     
  839.     def tkraise(self, aboveThis = None):
  840.         '''Raise this widget in the stacking order.'''
  841.         self.tk.call('raise', self._w, aboveThis)
  842.  
  843.     lift = tkraise
  844.     
  845.     def colormodel(self, value = None):
  846.         '''Useless. Not implemented in Tk.'''
  847.         return self.tk.call('tk', 'colormodel', self._w, value)
  848.  
  849.     
  850.     def winfo_atom(self, name, displayof = 0):
  851.         '''Return integer which represents atom NAME.'''
  852.         args = ('winfo', 'atom') + self._displayof(displayof) + (name,)
  853.         return getint(self.tk.call(args))
  854.  
  855.     
  856.     def winfo_atomname(self, id, displayof = 0):
  857.         '''Return name of atom with identifier ID.'''
  858.         args = ('winfo', 'atomname') + self._displayof(displayof) + (id,)
  859.         return self.tk.call(args)
  860.  
  861.     
  862.     def winfo_cells(self):
  863.         '''Return number of cells in the colormap for this widget.'''
  864.         return getint(self.tk.call('winfo', 'cells', self._w))
  865.  
  866.     
  867.     def winfo_children(self):
  868.         '''Return a list of all widgets which are children of this widget.'''
  869.         result = []
  870.         for child in self.tk.splitlist(self.tk.call('winfo', 'children', self._w)):
  871.             
  872.             try:
  873.                 result.append(self._nametowidget(child))
  874.             continue
  875.             except KeyError:
  876.                 continue
  877.             
  878.  
  879.         
  880.         return result
  881.  
  882.     
  883.     def winfo_class(self):
  884.         '''Return window class name of this widget.'''
  885.         return self.tk.call('winfo', 'class', self._w)
  886.  
  887.     
  888.     def winfo_colormapfull(self):
  889.         '''Return true if at the last color request the colormap was full.'''
  890.         return self.tk.getboolean(self.tk.call('winfo', 'colormapfull', self._w))
  891.  
  892.     
  893.     def winfo_containing(self, rootX, rootY, displayof = 0):
  894.         '''Return the widget which is at the root coordinates ROOTX, ROOTY.'''
  895.         args = ('winfo', 'containing') + self._displayof(displayof) + (rootX, rootY)
  896.         name = self.tk.call(args)
  897.         if not name:
  898.             return None
  899.         return self._nametowidget(name)
  900.  
  901.     
  902.     def winfo_depth(self):
  903.         '''Return the number of bits per pixel.'''
  904.         return getint(self.tk.call('winfo', 'depth', self._w))
  905.  
  906.     
  907.     def winfo_exists(self):
  908.         '''Return true if this widget exists.'''
  909.         return getint(self.tk.call('winfo', 'exists', self._w))
  910.  
  911.     
  912.     def winfo_fpixels(self, number):
  913.         '''Return the number of pixels for the given distance NUMBER
  914.         (e.g. "3c") as float.'''
  915.         return getdouble(self.tk.call('winfo', 'fpixels', self._w, number))
  916.  
  917.     
  918.     def winfo_geometry(self):
  919.         '''Return geometry string for this widget in the form "widthxheight+X+Y".'''
  920.         return self.tk.call('winfo', 'geometry', self._w)
  921.  
  922.     
  923.     def winfo_height(self):
  924.         '''Return height of this widget.'''
  925.         return getint(self.tk.call('winfo', 'height', self._w))
  926.  
  927.     
  928.     def winfo_id(self):
  929.         '''Return identifier ID for this widget.'''
  930.         return self.tk.getint(self.tk.call('winfo', 'id', self._w))
  931.  
  932.     
  933.     def winfo_interps(self, displayof = 0):
  934.         '''Return the name of all Tcl interpreters for this display.'''
  935.         args = ('winfo', 'interps') + self._displayof(displayof)
  936.         return self.tk.splitlist(self.tk.call(args))
  937.  
  938.     
  939.     def winfo_ismapped(self):
  940.         '''Return true if this widget is mapped.'''
  941.         return getint(self.tk.call('winfo', 'ismapped', self._w))
  942.  
  943.     
  944.     def winfo_manager(self):
  945.         '''Return the window mananger name for this widget.'''
  946.         return self.tk.call('winfo', 'manager', self._w)
  947.  
  948.     
  949.     def winfo_name(self):
  950.         '''Return the name of this widget.'''
  951.         return self.tk.call('winfo', 'name', self._w)
  952.  
  953.     
  954.     def winfo_parent(self):
  955.         '''Return the name of the parent of this widget.'''
  956.         return self.tk.call('winfo', 'parent', self._w)
  957.  
  958.     
  959.     def winfo_pathname(self, id, displayof = 0):
  960.         '''Return the pathname of the widget given by ID.'''
  961.         args = ('winfo', 'pathname') + self._displayof(displayof) + (id,)
  962.         return self.tk.call(args)
  963.  
  964.     
  965.     def winfo_pixels(self, number):
  966.         '''Rounded integer value of winfo_fpixels.'''
  967.         return getint(self.tk.call('winfo', 'pixels', self._w, number))
  968.  
  969.     
  970.     def winfo_pointerx(self):
  971.         '''Return the x coordinate of the pointer on the root window.'''
  972.         return getint(self.tk.call('winfo', 'pointerx', self._w))
  973.  
  974.     
  975.     def winfo_pointerxy(self):
  976.         '''Return a tuple of x and y coordinates of the pointer on the root window.'''
  977.         return self._getints(self.tk.call('winfo', 'pointerxy', self._w))
  978.  
  979.     
  980.     def winfo_pointery(self):
  981.         '''Return the y coordinate of the pointer on the root window.'''
  982.         return getint(self.tk.call('winfo', 'pointery', self._w))
  983.  
  984.     
  985.     def winfo_reqheight(self):
  986.         '''Return requested height of this widget.'''
  987.         return getint(self.tk.call('winfo', 'reqheight', self._w))
  988.  
  989.     
  990.     def winfo_reqwidth(self):
  991.         '''Return requested width of this widget.'''
  992.         return getint(self.tk.call('winfo', 'reqwidth', self._w))
  993.  
  994.     
  995.     def winfo_rgb(self, color):
  996.         '''Return tuple of decimal values for red, green, blue for
  997.         COLOR in this widget.'''
  998.         return self._getints(self.tk.call('winfo', 'rgb', self._w, color))
  999.  
  1000.     
  1001.     def winfo_rootx(self):
  1002.         '''Return x coordinate of upper left corner of this widget on the
  1003.         root window.'''
  1004.         return getint(self.tk.call('winfo', 'rootx', self._w))
  1005.  
  1006.     
  1007.     def winfo_rooty(self):
  1008.         '''Return y coordinate of upper left corner of this widget on the
  1009.         root window.'''
  1010.         return getint(self.tk.call('winfo', 'rooty', self._w))
  1011.  
  1012.     
  1013.     def winfo_screen(self):
  1014.         '''Return the screen name of this widget.'''
  1015.         return self.tk.call('winfo', 'screen', self._w)
  1016.  
  1017.     
  1018.     def winfo_screencells(self):
  1019.         '''Return the number of the cells in the colormap of the screen
  1020.         of this widget.'''
  1021.         return getint(self.tk.call('winfo', 'screencells', self._w))
  1022.  
  1023.     
  1024.     def winfo_screendepth(self):
  1025.         '''Return the number of bits per pixel of the root window of the
  1026.         screen of this widget.'''
  1027.         return getint(self.tk.call('winfo', 'screendepth', self._w))
  1028.  
  1029.     
  1030.     def winfo_screenheight(self):
  1031.         '''Return the number of pixels of the height of the screen of this widget
  1032.         in pixel.'''
  1033.         return getint(self.tk.call('winfo', 'screenheight', self._w))
  1034.  
  1035.     
  1036.     def winfo_screenmmheight(self):
  1037.         '''Return the number of pixels of the height of the screen of
  1038.         this widget in mm.'''
  1039.         return getint(self.tk.call('winfo', 'screenmmheight', self._w))
  1040.  
  1041.     
  1042.     def winfo_screenmmwidth(self):
  1043.         '''Return the number of pixels of the width of the screen of
  1044.         this widget in mm.'''
  1045.         return getint(self.tk.call('winfo', 'screenmmwidth', self._w))
  1046.  
  1047.     
  1048.     def winfo_screenvisual(self):
  1049.         '''Return one of the strings directcolor, grayscale, pseudocolor,
  1050.         staticcolor, staticgray, or truecolor for the default
  1051.         colormodel of this screen.'''
  1052.         return self.tk.call('winfo', 'screenvisual', self._w)
  1053.  
  1054.     
  1055.     def winfo_screenwidth(self):
  1056.         '''Return the number of pixels of the width of the screen of
  1057.         this widget in pixel.'''
  1058.         return getint(self.tk.call('winfo', 'screenwidth', self._w))
  1059.  
  1060.     
  1061.     def winfo_server(self):
  1062.         '''Return information of the X-Server of the screen of this widget in
  1063.         the form "XmajorRminor vendor vendorVersion".'''
  1064.         return self.tk.call('winfo', 'server', self._w)
  1065.  
  1066.     
  1067.     def winfo_toplevel(self):
  1068.         '''Return the toplevel widget of this widget.'''
  1069.         return self._nametowidget(self.tk.call('winfo', 'toplevel', self._w))
  1070.  
  1071.     
  1072.     def winfo_viewable(self):
  1073.         '''Return true if the widget and all its higher ancestors are mapped.'''
  1074.         return getint(self.tk.call('winfo', 'viewable', self._w))
  1075.  
  1076.     
  1077.     def winfo_visual(self):
  1078.         '''Return one of the strings directcolor, grayscale, pseudocolor,
  1079.         staticcolor, staticgray, or truecolor for the
  1080.         colormodel of this widget.'''
  1081.         return self.tk.call('winfo', 'visual', self._w)
  1082.  
  1083.     
  1084.     def winfo_visualid(self):
  1085.         '''Return the X identifier for the visual for this widget.'''
  1086.         return self.tk.call('winfo', 'visualid', self._w)
  1087.  
  1088.     
  1089.     def winfo_visualsavailable(self, includeids = 0):
  1090.         '''Return a list of all visuals available for the screen
  1091.         of this widget.
  1092.  
  1093.         Each item in the list consists of a visual name (see winfo_visual), a
  1094.         depth and if INCLUDEIDS=1 is given also the X identifier.'''
  1095.         if not includeids or 'includeids':
  1096.             pass
  1097.         data = self.tk.split(self.tk.call('winfo', 'visualsavailable', self._w, None))
  1098.         if type(data) is StringType:
  1099.             data = [
  1100.                 self.tk.split(data)]
  1101.         
  1102.         return map(self._Misc__winfo_parseitem, data)
  1103.  
  1104.     
  1105.     def __winfo_parseitem(self, t):
  1106.         '''Internal function.'''
  1107.         return t[:1] + tuple(map(self._Misc__winfo_getint, t[1:]))
  1108.  
  1109.     
  1110.     def __winfo_getint(self, x):
  1111.         '''Internal function.'''
  1112.         return int(x, 0)
  1113.  
  1114.     
  1115.     def winfo_vrootheight(self):
  1116.         '''Return the height of the virtual root window associated with this
  1117.         widget in pixels. If there is no virtual root window return the
  1118.         height of the screen.'''
  1119.         return getint(self.tk.call('winfo', 'vrootheight', self._w))
  1120.  
  1121.     
  1122.     def winfo_vrootwidth(self):
  1123.         '''Return the width of the virtual root window associated with this
  1124.         widget in pixel. If there is no virtual root window return the
  1125.         width of the screen.'''
  1126.         return getint(self.tk.call('winfo', 'vrootwidth', self._w))
  1127.  
  1128.     
  1129.     def winfo_vrootx(self):
  1130.         '''Return the x offset of the virtual root relative to the root
  1131.         window of the screen of this widget.'''
  1132.         return getint(self.tk.call('winfo', 'vrootx', self._w))
  1133.  
  1134.     
  1135.     def winfo_vrooty(self):
  1136.         '''Return the y offset of the virtual root relative to the root
  1137.         window of the screen of this widget.'''
  1138.         return getint(self.tk.call('winfo', 'vrooty', self._w))
  1139.  
  1140.     
  1141.     def winfo_width(self):
  1142.         '''Return the width of this widget.'''
  1143.         return getint(self.tk.call('winfo', 'width', self._w))
  1144.  
  1145.     
  1146.     def winfo_x(self):
  1147.         '''Return the x coordinate of the upper left corner of this widget
  1148.         in the parent.'''
  1149.         return getint(self.tk.call('winfo', 'x', self._w))
  1150.  
  1151.     
  1152.     def winfo_y(self):
  1153.         '''Return the y coordinate of the upper left corner of this widget
  1154.         in the parent.'''
  1155.         return getint(self.tk.call('winfo', 'y', self._w))
  1156.  
  1157.     
  1158.     def update(self):
  1159.         '''Enter event loop until all pending events have been processed by Tcl.'''
  1160.         self.tk.call('update')
  1161.  
  1162.     
  1163.     def update_idletasks(self):
  1164.         '''Enter event loop until all idle callbacks have been called. This
  1165.         will update the display of windows but not process events caused by
  1166.         the user.'''
  1167.         self.tk.call('update', 'idletasks')
  1168.  
  1169.     
  1170.     def bindtags(self, tagList = None):
  1171.         '''Set or get the list of bindtags for this widget.
  1172.  
  1173.         With no argument return the list of all bindtags associated with
  1174.         this widget. With a list of strings as argument the bindtags are
  1175.         set to this list. The bindtags determine in which order events are
  1176.         processed (see bind).'''
  1177.         if tagList is None:
  1178.             return self.tk.splitlist(self.tk.call('bindtags', self._w))
  1179.         self.tk.call('bindtags', self._w, tagList)
  1180.  
  1181.     
  1182.     def _bind(self, what, sequence, func, add, needcleanup = 1):
  1183.         '''Internal function.'''
  1184.         if type(func) is StringType:
  1185.             self.tk.call(what + (sequence, func))
  1186.         elif func:
  1187.             funcid = self._register(func, self._substitute, needcleanup)
  1188.             if not add or '+':
  1189.                 pass
  1190.             cmd = '%sif {"[%s %s]" == "break"} break\n' % ('', funcid, self._subst_format_str)
  1191.             self.tk.call(what + (sequence, cmd))
  1192.             return funcid
  1193.         if sequence:
  1194.             return self.tk.call(what + (sequence,))
  1195.         return self.tk.splitlist(self.tk.call(what))
  1196.  
  1197.     
  1198.     def bind(self, sequence = None, func = None, add = None):
  1199.         '''Bind to this widget at event SEQUENCE a call to function FUNC.
  1200.  
  1201.         SEQUENCE is a string of concatenated event
  1202.         patterns. An event pattern is of the form
  1203.         <MODIFIER-MODIFIER-TYPE-DETAIL> where MODIFIER is one
  1204.         of Control, Mod2, M2, Shift, Mod3, M3, Lock, Mod4, M4,
  1205.         Button1, B1, Mod5, M5 Button2, B2, Meta, M, Button3,
  1206.         B3, Alt, Button4, B4, Double, Button5, B5 Triple,
  1207.         Mod1, M1. TYPE is one of Activate, Enter, Map,
  1208.         ButtonPress, Button, Expose, Motion, ButtonRelease
  1209.         FocusIn, MouseWheel, Circulate, FocusOut, Property,
  1210.         Colormap, Gravity Reparent, Configure, KeyPress, Key,
  1211.         Unmap, Deactivate, KeyRelease Visibility, Destroy,
  1212.         Leave and DETAIL is the button number for ButtonPress,
  1213.         ButtonRelease and DETAIL is the Keysym for KeyPress and
  1214.         KeyRelease. Examples are
  1215.         <Control-Button-1> for pressing Control and mouse button 1 or
  1216.         <Alt-A> for pressing A and the Alt key (KeyPress can be omitted).
  1217.         An event pattern can also be a virtual event of the form
  1218.         <<AString>> where AString can be arbitrary. This
  1219.         event can be generated by event_generate.
  1220.         If events are concatenated they must appear shortly
  1221.         after each other.
  1222.  
  1223.         FUNC will be called if the event sequence occurs with an
  1224.         instance of Event as argument. If the return value of FUNC is
  1225.         "break" no further bound function is invoked.
  1226.  
  1227.         An additional boolean parameter ADD specifies whether FUNC will
  1228.         be called additionally to the other bound function or whether
  1229.         it will replace the previous function.
  1230.  
  1231.         Bind will return an identifier to allow deletion of the bound function with
  1232.         unbind without memory leak.
  1233.  
  1234.         If FUNC or SEQUENCE is omitted the bound function or list
  1235.         of bound events are returned.'''
  1236.         return self._bind(('bind', self._w), sequence, func, add)
  1237.  
  1238.     
  1239.     def unbind(self, sequence, funcid = None):
  1240.         '''Unbind for this widget for event SEQUENCE  the
  1241.         function identified with FUNCID.'''
  1242.         self.tk.call('bind', self._w, sequence, '')
  1243.         if funcid:
  1244.             self.deletecommand(funcid)
  1245.         
  1246.  
  1247.     
  1248.     def bind_all(self, sequence = None, func = None, add = None):
  1249.         '''Bind to all widgets at an event SEQUENCE a call to function FUNC.
  1250.         An additional boolean parameter ADD specifies whether FUNC will
  1251.         be called additionally to the other bound function or whether
  1252.         it will replace the previous function. See bind for the return value.'''
  1253.         return self._bind(('bind', 'all'), sequence, func, add, 0)
  1254.  
  1255.     
  1256.     def unbind_all(self, sequence):
  1257.         '''Unbind for all widgets for event SEQUENCE all functions.'''
  1258.         self.tk.call('bind', 'all', sequence, '')
  1259.  
  1260.     
  1261.     def bind_class(self, className, sequence = None, func = None, add = None):
  1262.         '''Bind to widgets with bindtag CLASSNAME at event
  1263.         SEQUENCE a call of function FUNC. An additional
  1264.         boolean parameter ADD specifies whether FUNC will be
  1265.         called additionally to the other bound function or
  1266.         whether it will replace the previous function. See bind for
  1267.         the return value.'''
  1268.         return self._bind(('bind', className), sequence, func, add, 0)
  1269.  
  1270.     
  1271.     def unbind_class(self, className, sequence):
  1272.         '''Unbind for a all widgets with bindtag CLASSNAME for event SEQUENCE
  1273.         all functions.'''
  1274.         self.tk.call('bind', className, sequence, '')
  1275.  
  1276.     
  1277.     def mainloop(self, n = 0):
  1278.         '''Call the mainloop of Tk.'''
  1279.         self.tk.mainloop(n)
  1280.  
  1281.     
  1282.     def quit(self):
  1283.         '''Quit the Tcl interpreter. All widgets will be destroyed.'''
  1284.         self.tk.quit()
  1285.  
  1286.     
  1287.     def _getints(self, string):
  1288.         '''Internal function.'''
  1289.         if string:
  1290.             return tuple(map(getint, self.tk.splitlist(string)))
  1291.  
  1292.     
  1293.     def _getdoubles(self, string):
  1294.         '''Internal function.'''
  1295.         if string:
  1296.             return tuple(map(getdouble, self.tk.splitlist(string)))
  1297.  
  1298.     
  1299.     def _getboolean(self, string):
  1300.         '''Internal function.'''
  1301.         if string:
  1302.             return self.tk.getboolean(string)
  1303.  
  1304.     
  1305.     def _displayof(self, displayof):
  1306.         '''Internal function.'''
  1307.         if displayof:
  1308.             return ('-displayof', displayof)
  1309.         if displayof is None:
  1310.             return ('-displayof', self._w)
  1311.         return ()
  1312.  
  1313.     
  1314.     def _options(self, cnf, kw = None):
  1315.         '''Internal function.'''
  1316.         if kw:
  1317.             cnf = _cnfmerge((cnf, kw))
  1318.         else:
  1319.             cnf = _cnfmerge(cnf)
  1320.         res = ()
  1321.         for k, v in cnf.items():
  1322.             if v is not None:
  1323.                 if k[-1] == '_':
  1324.                     k = k[:-1]
  1325.                 
  1326.                 if callable(v):
  1327.                     v = self._register(v)
  1328.                 elif isinstance(v, (tuple, list)):
  1329.                     nv = []
  1330.                     for item in v:
  1331.                         if not isinstance(item, (basestring, int)):
  1332.                             break
  1333.                             continue
  1334.                         if isinstance(item, int):
  1335.                             nv.append('%d' % item)
  1336.                             continue
  1337.                         None(nv.append if ' ' in item else '%s' % item)
  1338.                     else:
  1339.                         v = ' '.join(nv)
  1340.                 
  1341.                 res = res + ('-' + k, v)
  1342.                 continue
  1343.         
  1344.         return res
  1345.  
  1346.     
  1347.     def nametowidget(self, name):
  1348.         '''Return the Tkinter instance of a widget identified by
  1349.         its Tcl name NAME.'''
  1350.         name = str(name).split('.')
  1351.         w = self
  1352.         if not name[0]:
  1353.             w = w._root()
  1354.             name = name[1:]
  1355.         
  1356.         for n in name:
  1357.             if not n:
  1358.                 break
  1359.             
  1360.             w = w.children[n]
  1361.         
  1362.         return w
  1363.  
  1364.     _nametowidget = nametowidget
  1365.     
  1366.     def _register(self, func, subst = None, needcleanup = 1):
  1367.         '''Return a newly created Tcl function. If this
  1368.         function is called, the Python function FUNC will
  1369.         be executed. An optional function SUBST can
  1370.         be given which will be executed before FUNC.'''
  1371.         f = CallWrapper(func, subst, self).__call__
  1372.         name = repr(id(f))
  1373.         
  1374.         try:
  1375.             func = func.im_func
  1376.         except AttributeError:
  1377.             pass
  1378.  
  1379.         
  1380.         try:
  1381.             name = name + func.__name__
  1382.         except AttributeError:
  1383.             pass
  1384.  
  1385.         self.tk.createcommand(name, f)
  1386.         if needcleanup:
  1387.             if self._tclCommands is None:
  1388.                 self._tclCommands = []
  1389.             
  1390.             self._tclCommands.append(name)
  1391.         
  1392.         return name
  1393.  
  1394.     register = _register
  1395.     
  1396.     def _root(self):
  1397.         '''Internal function.'''
  1398.         w = self
  1399.         while w.master:
  1400.             w = w.master
  1401.         return w
  1402.  
  1403.     _subst_format = ('%#', '%b', '%f', '%h', '%k', '%s', '%t', '%w', '%x', '%y', '%A', '%E', '%K', '%N', '%W', '%T', '%X', '%Y', '%D')
  1404.     _subst_format_str = ' '.join(_subst_format)
  1405.     
  1406.     def _substitute(self, *args):
  1407.         '''Internal function.'''
  1408.         if len(args) != len(self._subst_format):
  1409.             return args
  1410.         getboolean = self.tk.getboolean
  1411.         getint = int
  1412.         
  1413.         def getint_event(s):
  1414.             '''Tk changed behavior in 8.4.2, returning "??" rather more often.'''
  1415.             
  1416.             try:
  1417.                 return int(s)
  1418.             except ValueError:
  1419.                 return s
  1420.  
  1421.  
  1422.         (nsign, b, f, h, k, s, t, w, x, y, A, E, K, N, W, T, X, Y, D) = args
  1423.         e = Event()
  1424.         e.serial = getint(nsign)
  1425.         e.num = getint_event(b)
  1426.         
  1427.         try:
  1428.             e.focus = getboolean(f)
  1429.         except TclError:
  1430.             len(args) != len(self._subst_format)
  1431.             len(args) != len(self._subst_format)
  1432.         except:
  1433.             len(args) != len(self._subst_format)
  1434.  
  1435.         e.height = getint_event(h)
  1436.         e.keycode = getint_event(k)
  1437.         e.state = getint_event(s)
  1438.         e.time = getint_event(t)
  1439.         e.width = getint_event(w)
  1440.         e.x = getint_event(x)
  1441.         e.y = getint_event(y)
  1442.         e.char = A
  1443.         
  1444.         try:
  1445.             e.send_event = getboolean(E)
  1446.         except TclError:
  1447.             len(args) != len(self._subst_format)
  1448.             len(args) != len(self._subst_format)
  1449.         except:
  1450.             len(args) != len(self._subst_format)
  1451.  
  1452.         e.keysym = K
  1453.         e.keysym_num = getint_event(N)
  1454.         e.type = T
  1455.         
  1456.         try:
  1457.             e.widget = self._nametowidget(W)
  1458.         except KeyError:
  1459.             len(args) != len(self._subst_format)
  1460.             len(args) != len(self._subst_format)
  1461.             e.widget = W
  1462.         except:
  1463.             len(args) != len(self._subst_format)
  1464.  
  1465.         e.x_root = getint_event(X)
  1466.         e.y_root = getint_event(Y)
  1467.         
  1468.         try:
  1469.             e.delta = getint(D)
  1470.         except ValueError:
  1471.             len(args) != len(self._subst_format)
  1472.             len(args) != len(self._subst_format)
  1473.             e.delta = 0
  1474.         except:
  1475.             len(args) != len(self._subst_format)
  1476.  
  1477.         return (e,)
  1478.  
  1479.     
  1480.     def _report_exception(self):
  1481.         '''Internal function.'''
  1482.         import sys as sys
  1483.         exc = sys.exc_type
  1484.         val = sys.exc_value
  1485.         tb = sys.exc_traceback
  1486.         root = self._root()
  1487.         root.report_callback_exception(exc, val, tb)
  1488.  
  1489.     
  1490.     def _configure(self, cmd, cnf, kw):
  1491.         '''Internal function.'''
  1492.         if kw:
  1493.             cnf = _cnfmerge((cnf, kw))
  1494.         elif cnf:
  1495.             cnf = _cnfmerge(cnf)
  1496.         
  1497.         if cnf is None:
  1498.             cnf = { }
  1499.             for x in self.tk.split(self.tk.call(_flatten((self._w, cmd)))):
  1500.                 cnf[x[0][1:]] = (x[0][1:],) + x[1:]
  1501.             
  1502.             return cnf
  1503.         if type(cnf) is StringType:
  1504.             x = self.tk.split(self.tk.call(_flatten((self._w, cmd, '-' + cnf))))
  1505.             return (x[0][1:],) + x[1:]
  1506.         self.tk.call(_flatten((self._w, cmd)) + self._options(cnf))
  1507.  
  1508.     
  1509.     def configure(self, cnf = None, **kw):
  1510.         '''Configure resources of a widget.
  1511.  
  1512.         The values for resources are specified as keyword
  1513.         arguments. To get an overview about
  1514.         the allowed keyword arguments call the method keys.
  1515.         '''
  1516.         return self._configure('configure', cnf, kw)
  1517.  
  1518.     config = configure
  1519.     
  1520.     def cget(self, key):
  1521.         '''Return the resource value for a KEY given as string.'''
  1522.         return self.tk.call(self._w, 'cget', '-' + key)
  1523.  
  1524.     __getitem__ = cget
  1525.     
  1526.     def __setitem__(self, key, value):
  1527.         self.configure({
  1528.             key: value })
  1529.  
  1530.     
  1531.     def __contains__(self, key):
  1532.         raise TypeError("Tkinter objects don't support 'in' tests.")
  1533.  
  1534.     
  1535.     def keys(self):
  1536.         '''Return a list of all resource names of this widget.'''
  1537.         return map((lambda x: x[0][1:]), self.tk.split(self.tk.call(self._w, 'configure')))
  1538.  
  1539.     
  1540.     def __str__(self):
  1541.         '''Return the window path name of this widget.'''
  1542.         return self._w
  1543.  
  1544.     _noarg_ = [
  1545.         '_noarg_']
  1546.     
  1547.     def pack_propagate(self, flag = _noarg_):
  1548.         '''Set or get the status for propagation of geometry information.
  1549.  
  1550.         A boolean argument specifies whether the geometry information
  1551.         of the slaves will determine the size of this widget. If no argument
  1552.         is given the current setting will be returned.
  1553.         '''
  1554.         if flag is Misc._noarg_:
  1555.             return self._getboolean(self.tk.call('pack', 'propagate', self._w))
  1556.         self.tk.call('pack', 'propagate', self._w, flag)
  1557.  
  1558.     propagate = pack_propagate
  1559.     
  1560.     def pack_slaves(self):
  1561.         '''Return a list of all slaves of this widget
  1562.         in its packing order.'''
  1563.         return map(self._nametowidget, self.tk.splitlist(self.tk.call('pack', 'slaves', self._w)))
  1564.  
  1565.     slaves = pack_slaves
  1566.     
  1567.     def place_slaves(self):
  1568.         '''Return a list of all slaves of this widget
  1569.         in its packing order.'''
  1570.         return map(self._nametowidget, self.tk.splitlist(self.tk.call('place', 'slaves', self._w)))
  1571.  
  1572.     
  1573.     def grid_bbox(self, column = None, row = None, col2 = None, row2 = None):
  1574.         '''Return a tuple of integer coordinates for the bounding
  1575.         box of this widget controlled by the geometry manager grid.
  1576.  
  1577.         If COLUMN, ROW is given the bounding box applies from
  1578.         the cell with row and column 0 to the specified
  1579.         cell. If COL2 and ROW2 are given the bounding box
  1580.         starts at that cell.
  1581.  
  1582.         The returned integers specify the offset of the upper left
  1583.         corner in the master widget and the width and height.
  1584.         '''
  1585.         args = ('grid', 'bbox', self._w)
  1586.         if column is not None and row is not None:
  1587.             args = args + (column, row)
  1588.         
  1589.         if col2 is not None and row2 is not None:
  1590.             args = args + (col2, row2)
  1591.         
  1592.         if not self._getints(self.tk.call(*args)):
  1593.             pass
  1594.  
  1595.     bbox = grid_bbox
  1596.     
  1597.     def _grid_configure(self, command, index, cnf, kw):
  1598.         '''Internal function.'''
  1599.         if type(cnf) is StringType and not kw:
  1600.             if cnf[-1:] == '_':
  1601.                 cnf = cnf[:-1]
  1602.             
  1603.             if cnf[:1] != '-':
  1604.                 cnf = '-' + cnf
  1605.             
  1606.             options = (cnf,)
  1607.         else:
  1608.             options = self._options(cnf, kw)
  1609.         if not options:
  1610.             res = self.tk.call('grid', command, self._w, index)
  1611.             words = self.tk.splitlist(res)
  1612.             dict = { }
  1613.             for i in range(0, len(words), 2):
  1614.                 key = words[i][1:]
  1615.                 value = words[i + 1]
  1616.                 if not value:
  1617.                     value = None
  1618.                 elif '.' in value:
  1619.                     value = getdouble(value)
  1620.                 else:
  1621.                     value = getint(value)
  1622.                 dict[key] = value
  1623.             
  1624.             return dict
  1625.         res = self.tk.call(('grid', command, self._w, index) + options)
  1626.         if len(options) == 1:
  1627.             if not res:
  1628.                 return None
  1629.             if '.' in res:
  1630.                 return getdouble(res)
  1631.             return getint(res)
  1632.  
  1633.     
  1634.     def grid_columnconfigure(self, index, cnf = { }, **kw):
  1635.         '''Configure column INDEX of a grid.
  1636.  
  1637.         Valid resources are minsize (minimum size of the column),
  1638.         weight (how much does additional space propagate to this column)
  1639.         and pad (how much space to let additionally).'''
  1640.         return self._grid_configure('columnconfigure', index, cnf, kw)
  1641.  
  1642.     columnconfigure = grid_columnconfigure
  1643.     
  1644.     def grid_location(self, x, y):
  1645.         '''Return a tuple of column and row which identify the cell
  1646.         at which the pixel at position X and Y inside the master
  1647.         widget is located.'''
  1648.         if not self._getints(self.tk.call('grid', 'location', self._w, x, y)):
  1649.             pass
  1650.  
  1651.     
  1652.     def grid_propagate(self, flag = _noarg_):
  1653.         '''Set or get the status for propagation of geometry information.
  1654.  
  1655.         A boolean argument specifies whether the geometry information
  1656.         of the slaves will determine the size of this widget. If no argument
  1657.         is given, the current setting will be returned.
  1658.         '''
  1659.         if flag is Misc._noarg_:
  1660.             return self._getboolean(self.tk.call('grid', 'propagate', self._w))
  1661.         self.tk.call('grid', 'propagate', self._w, flag)
  1662.  
  1663.     
  1664.     def grid_rowconfigure(self, index, cnf = { }, **kw):
  1665.         '''Configure row INDEX of a grid.
  1666.  
  1667.         Valid resources are minsize (minimum size of the row),
  1668.         weight (how much does additional space propagate to this row)
  1669.         and pad (how much space to let additionally).'''
  1670.         return self._grid_configure('rowconfigure', index, cnf, kw)
  1671.  
  1672.     rowconfigure = grid_rowconfigure
  1673.     
  1674.     def grid_size(self):
  1675.         '''Return a tuple of the number of column and rows in the grid.'''
  1676.         if not self._getints(self.tk.call('grid', 'size', self._w)):
  1677.             pass
  1678.  
  1679.     size = grid_size
  1680.     
  1681.     def grid_slaves(self, row = None, column = None):
  1682.         '''Return a list of all slaves of this widget
  1683.         in its packing order.'''
  1684.         args = ()
  1685.         if row is not None:
  1686.             args = args + ('-row', row)
  1687.         
  1688.         if column is not None:
  1689.             args = args + ('-column', column)
  1690.         
  1691.         return map(self._nametowidget, self.tk.splitlist(self.tk.call(('grid', 'slaves', self._w) + args)))
  1692.  
  1693.     
  1694.     def event_add(self, virtual, *sequences):
  1695.         '''Bind a virtual event VIRTUAL (of the form <<Name>>)
  1696.         to an event SEQUENCE such that the virtual event is triggered
  1697.         whenever SEQUENCE occurs.'''
  1698.         args = ('event', 'add', virtual) + sequences
  1699.         self.tk.call(args)
  1700.  
  1701.     
  1702.     def event_delete(self, virtual, *sequences):
  1703.         '''Unbind a virtual event VIRTUAL from SEQUENCE.'''
  1704.         args = ('event', 'delete', virtual) + sequences
  1705.         self.tk.call(args)
  1706.  
  1707.     
  1708.     def event_generate(self, sequence, **kw):
  1709.         '''Generate an event SEQUENCE. Additional
  1710.         keyword arguments specify parameter of the event
  1711.         (e.g. x, y, rootx, rooty).'''
  1712.         args = ('event', 'generate', self._w, sequence)
  1713.         for k, v in kw.items():
  1714.             args = args + ('-%s' % k, str(v))
  1715.         
  1716.         self.tk.call(args)
  1717.  
  1718.     
  1719.     def event_info(self, virtual = None):
  1720.         '''Return a list of all virtual events or the information
  1721.         about the SEQUENCE bound to the virtual event VIRTUAL.'''
  1722.         return self.tk.splitlist(self.tk.call('event', 'info', virtual))
  1723.  
  1724.     
  1725.     def image_names(self):
  1726.         '''Return a list of all existing image names.'''
  1727.         return self.tk.call('image', 'names')
  1728.  
  1729.     
  1730.     def image_types(self):
  1731.         '''Return a list of all available image types (e.g. phote bitmap).'''
  1732.         return self.tk.call('image', 'types')
  1733.  
  1734.  
  1735.  
  1736. class CallWrapper:
  1737.     '''Internal class. Stores function to call when some user
  1738.     defined Tcl function is called e.g. after an event occurred.'''
  1739.     
  1740.     def __init__(self, func, subst, widget):
  1741.         '''Store FUNC, SUBST and WIDGET as members.'''
  1742.         self.func = func
  1743.         self.subst = subst
  1744.         self.widget = widget
  1745.  
  1746.     
  1747.     def __call__(self, *args):
  1748.         '''Apply first function SUBST to arguments, than FUNC.'''
  1749.         
  1750.         try:
  1751.             if self.subst:
  1752.                 args = self.subst(*args)
  1753.             
  1754.             return self.func(*args)
  1755.         except SystemExit:
  1756.             msg = None
  1757.             raise SystemExit, msg
  1758.         except:
  1759.             self.widget._report_exception()
  1760.  
  1761.  
  1762.  
  1763.  
  1764. class Wm:
  1765.     '''Provides functions for the communication with the window manager.'''
  1766.     
  1767.     def wm_aspect(self, minNumer = None, minDenom = None, maxNumer = None, maxDenom = None):
  1768.         '''Instruct the window manager to set the aspect ratio (width/height)
  1769.         of this widget to be between MINNUMER/MINDENOM and MAXNUMER/MAXDENOM. Return a tuple
  1770.         of the actual values if no argument is given.'''
  1771.         return self._getints(self.tk.call('wm', 'aspect', self._w, minNumer, minDenom, maxNumer, maxDenom))
  1772.  
  1773.     aspect = wm_aspect
  1774.     
  1775.     def wm_attributes(self, *args):
  1776.         '''This subcommand returns or sets platform specific attributes
  1777.  
  1778.         The first form returns a list of the platform specific flags and
  1779.         their values. The second form returns the value for the specific
  1780.         option. The third form sets one or more of the values. The values
  1781.         are as follows:
  1782.  
  1783.         On Windows, -disabled gets or sets whether the window is in a
  1784.         disabled state. -toolwindow gets or sets the style of the window
  1785.         to toolwindow (as defined in the MSDN). -topmost gets or sets
  1786.         whether this is a topmost window (displays above all other
  1787.         windows).
  1788.  
  1789.         On Macintosh, XXXXX
  1790.  
  1791.         On Unix, there are currently no special attribute values.
  1792.         '''
  1793.         args = ('wm', 'attributes', self._w) + args
  1794.         return self.tk.call(args)
  1795.  
  1796.     attributes = wm_attributes
  1797.     
  1798.     def wm_client(self, name = None):
  1799.         '''Store NAME in WM_CLIENT_MACHINE property of this widget. Return
  1800.         current value.'''
  1801.         return self.tk.call('wm', 'client', self._w, name)
  1802.  
  1803.     client = wm_client
  1804.     
  1805.     def wm_colormapwindows(self, *wlist):
  1806.         '''Store list of window names (WLIST) into WM_COLORMAPWINDOWS property
  1807.         of this widget. This list contains windows whose colormaps differ from their
  1808.         parents. Return current list of widgets if WLIST is empty.'''
  1809.         if len(wlist) > 1:
  1810.             wlist = (wlist,)
  1811.         
  1812.         args = ('wm', 'colormapwindows', self._w) + wlist
  1813.         return map(self._nametowidget, self.tk.call(args))
  1814.  
  1815.     colormapwindows = wm_colormapwindows
  1816.     
  1817.     def wm_command(self, value = None):
  1818.         '''Store VALUE in WM_COMMAND property. It is the command
  1819.         which shall be used to invoke the application. Return current
  1820.         command if VALUE is None.'''
  1821.         return self.tk.call('wm', 'command', self._w, value)
  1822.  
  1823.     command = wm_command
  1824.     
  1825.     def wm_deiconify(self):
  1826.         '''Deiconify this widget. If it was never mapped it will not be mapped.
  1827.         On Windows it will raise this widget and give it the focus.'''
  1828.         return self.tk.call('wm', 'deiconify', self._w)
  1829.  
  1830.     deiconify = wm_deiconify
  1831.     
  1832.     def wm_focusmodel(self, model = None):
  1833.         '''Set focus model to MODEL. "active" means that this widget will claim
  1834.         the focus itself, "passive" means that the window manager shall give
  1835.         the focus. Return current focus model if MODEL is None.'''
  1836.         return self.tk.call('wm', 'focusmodel', self._w, model)
  1837.  
  1838.     focusmodel = wm_focusmodel
  1839.     
  1840.     def wm_frame(self):
  1841.         '''Return identifier for decorative frame of this widget if present.'''
  1842.         return self.tk.call('wm', 'frame', self._w)
  1843.  
  1844.     frame = wm_frame
  1845.     
  1846.     def wm_geometry(self, newGeometry = None):
  1847.         '''Set geometry to NEWGEOMETRY of the form =widthxheight+x+y. Return
  1848.         current value if None is given.'''
  1849.         return self.tk.call('wm', 'geometry', self._w, newGeometry)
  1850.  
  1851.     geometry = wm_geometry
  1852.     
  1853.     def wm_grid(self, baseWidth = None, baseHeight = None, widthInc = None, heightInc = None):
  1854.         '''Instruct the window manager that this widget shall only be
  1855.         resized on grid boundaries. WIDTHINC and HEIGHTINC are the width and
  1856.         height of a grid unit in pixels. BASEWIDTH and BASEHEIGHT are the
  1857.         number of grid units requested in Tk_GeometryRequest.'''
  1858.         return self._getints(self.tk.call('wm', 'grid', self._w, baseWidth, baseHeight, widthInc, heightInc))
  1859.  
  1860.     grid = wm_grid
  1861.     
  1862.     def wm_group(self, pathName = None):
  1863.         '''Set the group leader widgets for related widgets to PATHNAME. Return
  1864.         the group leader of this widget if None is given.'''
  1865.         return self.tk.call('wm', 'group', self._w, pathName)
  1866.  
  1867.     group = wm_group
  1868.     
  1869.     def wm_iconbitmap(self, bitmap = None, default = None):
  1870.         """Set bitmap for the iconified widget to BITMAP. Return
  1871.         the bitmap if None is given.
  1872.  
  1873.         Under Windows, the DEFAULT parameter can be used to set the icon
  1874.         for the widget and any descendents that don't have an icon set
  1875.         explicitly.  DEFAULT can be the relative path to a .ico file
  1876.         (example: root.iconbitmap(default='myicon.ico') ).  See Tk
  1877.         documentation for more information."""
  1878.         if default:
  1879.             return self.tk.call('wm', 'iconbitmap', self._w, '-default', default)
  1880.         return self.tk.call('wm', 'iconbitmap', self._w, bitmap)
  1881.  
  1882.     iconbitmap = wm_iconbitmap
  1883.     
  1884.     def wm_iconify(self):
  1885.         '''Display widget as icon.'''
  1886.         return self.tk.call('wm', 'iconify', self._w)
  1887.  
  1888.     iconify = wm_iconify
  1889.     
  1890.     def wm_iconmask(self, bitmap = None):
  1891.         '''Set mask for the icon bitmap of this widget. Return the
  1892.         mask if None is given.'''
  1893.         return self.tk.call('wm', 'iconmask', self._w, bitmap)
  1894.  
  1895.     iconmask = wm_iconmask
  1896.     
  1897.     def wm_iconname(self, newName = None):
  1898.         '''Set the name of the icon for this widget. Return the name if
  1899.         None is given.'''
  1900.         return self.tk.call('wm', 'iconname', self._w, newName)
  1901.  
  1902.     iconname = wm_iconname
  1903.     
  1904.     def wm_iconposition(self, x = None, y = None):
  1905.         '''Set the position of the icon of this widget to X and Y. Return
  1906.         a tuple of the current values of X and X if None is given.'''
  1907.         return self._getints(self.tk.call('wm', 'iconposition', self._w, x, y))
  1908.  
  1909.     iconposition = wm_iconposition
  1910.     
  1911.     def wm_iconwindow(self, pathName = None):
  1912.         '''Set widget PATHNAME to be displayed instead of icon. Return the current
  1913.         value if None is given.'''
  1914.         return self.tk.call('wm', 'iconwindow', self._w, pathName)
  1915.  
  1916.     iconwindow = wm_iconwindow
  1917.     
  1918.     def wm_maxsize(self, width = None, height = None):
  1919.         '''Set max WIDTH and HEIGHT for this widget. If the window is gridded
  1920.         the values are given in grid units. Return the current values if None
  1921.         is given.'''
  1922.         return self._getints(self.tk.call('wm', 'maxsize', self._w, width, height))
  1923.  
  1924.     maxsize = wm_maxsize
  1925.     
  1926.     def wm_minsize(self, width = None, height = None):
  1927.         '''Set min WIDTH and HEIGHT for this widget. If the window is gridded
  1928.         the values are given in grid units. Return the current values if None
  1929.         is given.'''
  1930.         return self._getints(self.tk.call('wm', 'minsize', self._w, width, height))
  1931.  
  1932.     minsize = wm_minsize
  1933.     
  1934.     def wm_overrideredirect(self, boolean = None):
  1935.         '''Instruct the window manager to ignore this widget
  1936.         if BOOLEAN is given with 1. Return the current value if None
  1937.         is given.'''
  1938.         return self._getboolean(self.tk.call('wm', 'overrideredirect', self._w, boolean))
  1939.  
  1940.     overrideredirect = wm_overrideredirect
  1941.     
  1942.     def wm_positionfrom(self, who = None):
  1943.         '''Instruct the window manager that the position of this widget shall
  1944.         be defined by the user if WHO is "user", and by its own policy if WHO is
  1945.         "program".'''
  1946.         return self.tk.call('wm', 'positionfrom', self._w, who)
  1947.  
  1948.     positionfrom = wm_positionfrom
  1949.     
  1950.     def wm_protocol(self, name = None, func = None):
  1951.         '''Bind function FUNC to command NAME for this widget.
  1952.         Return the function bound to NAME if None is given. NAME could be
  1953.         e.g. "WM_SAVE_YOURSELF" or "WM_DELETE_WINDOW".'''
  1954.         if hasattr(func, '__call__'):
  1955.             command = self._register(func)
  1956.         else:
  1957.             command = func
  1958.         return self.tk.call('wm', 'protocol', self._w, name, command)
  1959.  
  1960.     protocol = wm_protocol
  1961.     
  1962.     def wm_resizable(self, width = None, height = None):
  1963.         '''Instruct the window manager whether this width can be resized
  1964.         in WIDTH or HEIGHT. Both values are boolean values.'''
  1965.         return self.tk.call('wm', 'resizable', self._w, width, height)
  1966.  
  1967.     resizable = wm_resizable
  1968.     
  1969.     def wm_sizefrom(self, who = None):
  1970.         '''Instruct the window manager that the size of this widget shall
  1971.         be defined by the user if WHO is "user", and by its own policy if WHO is
  1972.         "program".'''
  1973.         return self.tk.call('wm', 'sizefrom', self._w, who)
  1974.  
  1975.     sizefrom = wm_sizefrom
  1976.     
  1977.     def wm_state(self, newstate = None):
  1978.         '''Query or set the state of this widget as one of normal, icon,
  1979.         iconic (see wm_iconwindow), withdrawn, or zoomed (Windows only).'''
  1980.         return self.tk.call('wm', 'state', self._w, newstate)
  1981.  
  1982.     state = wm_state
  1983.     
  1984.     def wm_title(self, string = None):
  1985.         '''Set the title of this widget.'''
  1986.         return self.tk.call('wm', 'title', self._w, string)
  1987.  
  1988.     title = wm_title
  1989.     
  1990.     def wm_transient(self, master = None):
  1991.         '''Instruct the window manager that this widget is transient
  1992.         with regard to widget MASTER.'''
  1993.         return self.tk.call('wm', 'transient', self._w, master)
  1994.  
  1995.     transient = wm_transient
  1996.     
  1997.     def wm_withdraw(self):
  1998.         '''Withdraw this widget from the screen such that it is unmapped
  1999.         and forgotten by the window manager. Re-draw it with wm_deiconify.'''
  2000.         return self.tk.call('wm', 'withdraw', self._w)
  2001.  
  2002.     withdraw = wm_withdraw
  2003.  
  2004.  
  2005. class Tk(Misc, Wm):
  2006.     '''Toplevel widget of Tk which represents mostly the main window
  2007.     of an appliation. It has an associated Tcl interpreter.'''
  2008.     _w = '.'
  2009.     
  2010.     def __init__(self, screenName = None, baseName = None, className = 'Tk', useTk = 1, sync = 0, use = None):
  2011.         '''Return a new Toplevel widget on screen SCREENNAME. A new Tcl interpreter will
  2012.         be created. BASENAME will be used for the identification of the profile file (see
  2013.         readprofile).
  2014.         It is constructed from sys.argv[0] without extensions if None is given. CLASSNAME
  2015.         is the name of the widget class.'''
  2016.         self.master = None
  2017.         self.children = { }
  2018.         self._tkloaded = 0
  2019.         self.tk = None
  2020.         if baseName is None:
  2021.             import sys
  2022.             import os as os
  2023.             baseName = os.path.basename(sys.argv[0])
  2024.             (baseName, ext) = os.path.splitext(baseName)
  2025.             if ext not in ('.py', '.pyc', '.pyo'):
  2026.                 baseName = baseName + ext
  2027.             
  2028.         
  2029.         interactive = 0
  2030.         self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
  2031.         if useTk:
  2032.             self._loadtk()
  2033.         
  2034.         self.readprofile(baseName, className)
  2035.  
  2036.     
  2037.     def loadtk(self):
  2038.         if not self._tkloaded:
  2039.             self.tk.loadtk()
  2040.             self._loadtk()
  2041.         
  2042.  
  2043.     
  2044.     def _loadtk(self):
  2045.         global _default_root
  2046.         self._tkloaded = 1
  2047.         tk_version = self.tk.getvar('tk_version')
  2048.         if tk_version != _tkinter.TK_VERSION:
  2049.             raise RuntimeError, "tk.h version (%s) doesn't match libtk.a version (%s)" % (_tkinter.TK_VERSION, tk_version)
  2050.         tk_version != _tkinter.TK_VERSION
  2051.         tcl_version = str(self.tk.getvar('tcl_version'))
  2052.         if tcl_version != _tkinter.TCL_VERSION:
  2053.             raise RuntimeError, "tcl.h version (%s) doesn't match libtcl.a version (%s)" % (_tkinter.TCL_VERSION, tcl_version)
  2054.         tcl_version != _tkinter.TCL_VERSION
  2055.         if TkVersion < 4:
  2056.             raise RuntimeError, 'Tk 4.0 or higher is required; found Tk %s' % str(TkVersion)
  2057.         TkVersion < 4
  2058.         if self._tclCommands is None:
  2059.             self._tclCommands = []
  2060.         
  2061.         self.tk.createcommand('tkerror', _tkerror)
  2062.         self.tk.createcommand('exit', _exit)
  2063.         self._tclCommands.append('tkerror')
  2064.         self._tclCommands.append('exit')
  2065.         if _support_default_root and not _default_root:
  2066.             _default_root = self
  2067.         
  2068.         self.protocol('WM_DELETE_WINDOW', self.destroy)
  2069.  
  2070.     
  2071.     def destroy(self):
  2072.         '''Destroy this and all descendants widgets. This will
  2073.         end the application of this Tcl interpreter.'''
  2074.         global _default_root
  2075.         for c in self.children.values():
  2076.             c.destroy()
  2077.         
  2078.         self.tk.call('destroy', self._w)
  2079.         Misc.destroy(self)
  2080.         if _support_default_root and _default_root is self:
  2081.             _default_root = None
  2082.         
  2083.  
  2084.     
  2085.     def readprofile(self, baseName, className):
  2086.         '''Internal function. It reads BASENAME.tcl and CLASSNAME.tcl into
  2087.         the Tcl Interpreter and calls execfile on BASENAME.py and CLASSNAME.py if
  2088.         such a file exists in the home directory.'''
  2089.         import os
  2090.         if os.environ.has_key('HOME'):
  2091.             home = os.environ['HOME']
  2092.         else:
  2093.             home = os.curdir
  2094.         class_tcl = os.path.join(home, '.%s.tcl' % className)
  2095.         class_py = os.path.join(home, '.%s.py' % className)
  2096.         base_tcl = os.path.join(home, '.%s.tcl' % baseName)
  2097.         base_py = os.path.join(home, '.%s.py' % baseName)
  2098.         dir = {
  2099.             'self': self }
  2100.         exec 'from Tkinter import *' in dir
  2101.         if os.path.isfile(class_tcl):
  2102.             self.tk.call('source', class_tcl)
  2103.         
  2104.         if os.path.isfile(class_py):
  2105.             execfile(class_py, dir)
  2106.         
  2107.         if os.path.isfile(base_tcl):
  2108.             self.tk.call('source', base_tcl)
  2109.         
  2110.         if os.path.isfile(base_py):
  2111.             execfile(base_py, dir)
  2112.         
  2113.  
  2114.     
  2115.     def report_callback_exception(self, exc, val, tb):
  2116.         '''Internal function. It reports exception on sys.stderr.'''
  2117.         import traceback as traceback
  2118.         import sys
  2119.         sys.stderr.write('Exception in Tkinter callback\n')
  2120.         sys.last_type = exc
  2121.         sys.last_value = val
  2122.         sys.last_traceback = tb
  2123.         traceback.print_exception(exc, val, tb)
  2124.  
  2125.     
  2126.     def __getattr__(self, attr):
  2127.         '''Delegate attribute access to the interpreter object'''
  2128.         return getattr(self.tk, attr)
  2129.  
  2130.  
  2131.  
  2132. def Tcl(screenName = None, baseName = None, className = 'Tk', useTk = 0):
  2133.     return Tk(screenName, baseName, className, useTk)
  2134.  
  2135.  
  2136. class Pack:
  2137.     '''Geometry manager Pack.
  2138.  
  2139.     Base class to use the methods pack_* in every widget.'''
  2140.     
  2141.     def pack_configure(self, cnf = { }, **kw):
  2142.         """Pack a widget in the parent widget. Use as options:
  2143.         after=widget - pack it after you have packed widget
  2144.         anchor=NSEW (or subset) - position widget according to
  2145.                                   given direction
  2146.         before=widget - pack it before you will pack widget
  2147.         expand=bool - expand widget if parent size grows
  2148.         fill=NONE or X or Y or BOTH - fill widget if widget grows
  2149.         in=master - use master to contain this widget
  2150.         in_=master - see 'in' option description
  2151.         ipadx=amount - add internal padding in x direction
  2152.         ipady=amount - add internal padding in y direction
  2153.         padx=amount - add padding in x direction
  2154.         pady=amount - add padding in y direction
  2155.         side=TOP or BOTTOM or LEFT or RIGHT -  where to add this widget.
  2156.         """
  2157.         self.tk.call(('pack', 'configure', self._w) + self._options(cnf, kw))
  2158.  
  2159.     pack = configure = config = pack_configure
  2160.     
  2161.     def pack_forget(self):
  2162.         '''Unmap this widget and do not use it for the packing order.'''
  2163.         self.tk.call('pack', 'forget', self._w)
  2164.  
  2165.     forget = pack_forget
  2166.     
  2167.     def pack_info(self):
  2168.         '''Return information about the packing options
  2169.         for this widget.'''
  2170.         words = self.tk.splitlist(self.tk.call('pack', 'info', self._w))
  2171.         dict = { }
  2172.         for i in range(0, len(words), 2):
  2173.             key = words[i][1:]
  2174.             value = words[i + 1]
  2175.             if value[:1] == '.':
  2176.                 value = self._nametowidget(value)
  2177.             
  2178.             dict[key] = value
  2179.         
  2180.         return dict
  2181.  
  2182.     info = pack_info
  2183.     propagate = pack_propagate = Misc.pack_propagate
  2184.     slaves = pack_slaves = Misc.pack_slaves
  2185.  
  2186.  
  2187. class Place:
  2188.     '''Geometry manager Place.
  2189.  
  2190.     Base class to use the methods place_* in every widget.'''
  2191.     
  2192.     def place_configure(self, cnf = { }, **kw):
  2193.         '''Place a widget in the parent widget. Use as options:
  2194.         in=master - master relative to which the widget is placed
  2195.         in_=master - see \'in\' option description
  2196.         x=amount - locate anchor of this widget at position x of master
  2197.         y=amount - locate anchor of this widget at position y of master
  2198.         relx=amount - locate anchor of this widget between 0.0 and 1.0
  2199.                       relative to width of master (1.0 is right edge)
  2200.         rely=amount - locate anchor of this widget between 0.0 and 1.0
  2201.                       relative to height of master (1.0 is bottom edge)
  2202.         anchor=NSEW (or subset) - position anchor according to given direction
  2203.         width=amount - width of this widget in pixel
  2204.         height=amount - height of this widget in pixel
  2205.         relwidth=amount - width of this widget between 0.0 and 1.0
  2206.                           relative to width of master (1.0 is the same width
  2207.                           as the master)
  2208.         relheight=amount - height of this widget between 0.0 and 1.0
  2209.                            relative to height of master (1.0 is the same
  2210.                            height as the master)
  2211.         bordermode="inside" or "outside" - whether to take border width of
  2212.                                            master widget into account
  2213.         '''
  2214.         self.tk.call(('place', 'configure', self._w) + self._options(cnf, kw))
  2215.  
  2216.     place = configure = config = place_configure
  2217.     
  2218.     def place_forget(self):
  2219.         '''Unmap this widget.'''
  2220.         self.tk.call('place', 'forget', self._w)
  2221.  
  2222.     forget = place_forget
  2223.     
  2224.     def place_info(self):
  2225.         '''Return information about the placing options
  2226.         for this widget.'''
  2227.         words = self.tk.splitlist(self.tk.call('place', 'info', self._w))
  2228.         dict = { }
  2229.         for i in range(0, len(words), 2):
  2230.             key = words[i][1:]
  2231.             value = words[i + 1]
  2232.             if value[:1] == '.':
  2233.                 value = self._nametowidget(value)
  2234.             
  2235.             dict[key] = value
  2236.         
  2237.         return dict
  2238.  
  2239.     info = place_info
  2240.     slaves = place_slaves = Misc.place_slaves
  2241.  
  2242.  
  2243. class Grid:
  2244.     '''Geometry manager Grid.
  2245.  
  2246.     Base class to use the methods grid_* in every widget.'''
  2247.     
  2248.     def grid_configure(self, cnf = { }, **kw):
  2249.         """Position a widget in the parent widget in a grid. Use as options:
  2250.         column=number - use cell identified with given column (starting with 0)
  2251.         columnspan=number - this widget will span several columns
  2252.         in=master - use master to contain this widget
  2253.         in_=master - see 'in' option description
  2254.         ipadx=amount - add internal padding in x direction
  2255.         ipady=amount - add internal padding in y direction
  2256.         padx=amount - add padding in x direction
  2257.         pady=amount - add padding in y direction
  2258.         row=number - use cell identified with given row (starting with 0)
  2259.         rowspan=number - this widget will span several rows
  2260.         sticky=NSEW - if cell is larger on which sides will this
  2261.                       widget stick to the cell boundary
  2262.         """
  2263.         self.tk.call(('grid', 'configure', self._w) + self._options(cnf, kw))
  2264.  
  2265.     grid = configure = config = grid_configure
  2266.     bbox = grid_bbox = Misc.grid_bbox
  2267.     columnconfigure = grid_columnconfigure = Misc.grid_columnconfigure
  2268.     
  2269.     def grid_forget(self):
  2270.         '''Unmap this widget.'''
  2271.         self.tk.call('grid', 'forget', self._w)
  2272.  
  2273.     forget = grid_forget
  2274.     
  2275.     def grid_remove(self):
  2276.         '''Unmap this widget but remember the grid options.'''
  2277.         self.tk.call('grid', 'remove', self._w)
  2278.  
  2279.     
  2280.     def grid_info(self):
  2281.         '''Return information about the options
  2282.         for positioning this widget in a grid.'''
  2283.         words = self.tk.splitlist(self.tk.call('grid', 'info', self._w))
  2284.         dict = { }
  2285.         for i in range(0, len(words), 2):
  2286.             key = words[i][1:]
  2287.             value = words[i + 1]
  2288.             if value[:1] == '.':
  2289.                 value = self._nametowidget(value)
  2290.             
  2291.             dict[key] = value
  2292.         
  2293.         return dict
  2294.  
  2295.     info = grid_info
  2296.     location = grid_location = Misc.grid_location
  2297.     propagate = grid_propagate = Misc.grid_propagate
  2298.     rowconfigure = grid_rowconfigure = Misc.grid_rowconfigure
  2299.     size = grid_size = Misc.grid_size
  2300.     slaves = grid_slaves = Misc.grid_slaves
  2301.  
  2302.  
  2303. class BaseWidget(Misc):
  2304.     '''Internal class.'''
  2305.     
  2306.     def _setup(self, master, cnf):
  2307.         '''Internal function. Sets up information about children.'''
  2308.         global _default_root
  2309.         if _support_default_root:
  2310.             if not master:
  2311.                 if not _default_root:
  2312.                     _default_root = Tk()
  2313.                 
  2314.                 master = _default_root
  2315.             
  2316.         
  2317.         self.master = master
  2318.         self.tk = master.tk
  2319.         name = None
  2320.         if cnf.has_key('name'):
  2321.             name = cnf['name']
  2322.             del cnf['name']
  2323.         
  2324.         if not name:
  2325.             name = repr(id(self))
  2326.         
  2327.         self._name = name
  2328.         if master._w == '.':
  2329.             self._w = '.' + name
  2330.         else:
  2331.             self._w = master._w + '.' + name
  2332.         self.children = { }
  2333.         if self.master.children.has_key(self._name):
  2334.             self.master.children[self._name].destroy()
  2335.         
  2336.         self.master.children[self._name] = self
  2337.  
  2338.     
  2339.     def __init__(self, master, widgetName, cnf = { }, kw = { }, extra = ()):
  2340.         '''Construct a widget with the parent widget MASTER, a name WIDGETNAME
  2341.         and appropriate options.'''
  2342.         if kw:
  2343.             cnf = _cnfmerge((cnf, kw))
  2344.         
  2345.         self.widgetName = widgetName
  2346.         BaseWidget._setup(self, master, cnf)
  2347.         if self._tclCommands is None:
  2348.             self._tclCommands = []
  2349.         
  2350.         classes = []
  2351.         for k in cnf.keys():
  2352.             if type(k) is ClassType:
  2353.                 classes.append((k, cnf[k]))
  2354.                 del cnf[k]
  2355.                 continue
  2356.         
  2357.         self.tk.call((widgetName, self._w) + extra + self._options(cnf))
  2358.         for k, v in classes:
  2359.             k.configure(self, v)
  2360.         
  2361.  
  2362.     
  2363.     def destroy(self):
  2364.         '''Destroy this and all descendants widgets.'''
  2365.         for c in self.children.values():
  2366.             c.destroy()
  2367.         
  2368.         self.tk.call('destroy', self._w)
  2369.         if self.master.children.has_key(self._name):
  2370.             del self.master.children[self._name]
  2371.         
  2372.         Misc.destroy(self)
  2373.  
  2374.     
  2375.     def _do(self, name, args = ()):
  2376.         return self.tk.call((self._w, name) + args)
  2377.  
  2378.  
  2379.  
  2380. class Widget(BaseWidget, Pack, Place, Grid):
  2381.     '''Internal class.
  2382.  
  2383.     Base class for a widget which can be positioned with the geometry managers
  2384.     Pack, Place or Grid.'''
  2385.     pass
  2386.  
  2387.  
  2388. class Toplevel(BaseWidget, Wm):
  2389.     '''Toplevel widget, e.g. for dialogs.'''
  2390.     
  2391.     def __init__(self, master = None, cnf = { }, **kw):
  2392.         '''Construct a toplevel widget with the parent MASTER.
  2393.  
  2394.         Valid resource names: background, bd, bg, borderwidth, class,
  2395.         colormap, container, cursor, height, highlightbackground,
  2396.         highlightcolor, highlightthickness, menu, relief, screen, takefocus,
  2397.         use, visual, width.'''
  2398.         if kw:
  2399.             cnf = _cnfmerge((cnf, kw))
  2400.         
  2401.         extra = ()
  2402.         for wmkey in [
  2403.             'screen',
  2404.             'class_',
  2405.             'class',
  2406.             'visual',
  2407.             'colormap']:
  2408.             if cnf.has_key(wmkey):
  2409.                 val = cnf[wmkey]
  2410.                 if wmkey[-1] == '_':
  2411.                     opt = '-' + wmkey[:-1]
  2412.                 else:
  2413.                     opt = '-' + wmkey
  2414.                 extra = extra + (opt, val)
  2415.                 del cnf[wmkey]
  2416.                 continue
  2417.         
  2418.         BaseWidget.__init__(self, master, 'toplevel', cnf, { }, extra)
  2419.         root = self._root()
  2420.         self.iconname(root.iconname())
  2421.         self.title(root.title())
  2422.         self.protocol('WM_DELETE_WINDOW', self.destroy)
  2423.  
  2424.  
  2425.  
  2426. class Button(Widget):
  2427.     '''Button widget.'''
  2428.     
  2429.     def __init__(self, master = None, cnf = { }, **kw):
  2430.         '''Construct a button widget with the parent MASTER.
  2431.  
  2432.         STANDARD OPTIONS
  2433.  
  2434.             activebackground, activeforeground, anchor,
  2435.             background, bitmap, borderwidth, cursor,
  2436.             disabledforeground, font, foreground
  2437.             highlightbackground, highlightcolor,
  2438.             highlightthickness, image, justify,
  2439.             padx, pady, relief, repeatdelay,
  2440.             repeatinterval, takefocus, text,
  2441.             textvariable, underline, wraplength
  2442.  
  2443.         WIDGET-SPECIFIC OPTIONS
  2444.  
  2445.             command, compound, default, height,
  2446.             overrelief, state, width
  2447.         '''
  2448.         Widget.__init__(self, master, 'button', cnf, kw)
  2449.  
  2450.     
  2451.     def tkButtonEnter(self, *dummy):
  2452.         self.tk.call('tkButtonEnter', self._w)
  2453.  
  2454.     
  2455.     def tkButtonLeave(self, *dummy):
  2456.         self.tk.call('tkButtonLeave', self._w)
  2457.  
  2458.     
  2459.     def tkButtonDown(self, *dummy):
  2460.         self.tk.call('tkButtonDown', self._w)
  2461.  
  2462.     
  2463.     def tkButtonUp(self, *dummy):
  2464.         self.tk.call('tkButtonUp', self._w)
  2465.  
  2466.     
  2467.     def tkButtonInvoke(self, *dummy):
  2468.         self.tk.call('tkButtonInvoke', self._w)
  2469.  
  2470.     
  2471.     def flash(self):
  2472.         """Flash the button.
  2473.  
  2474.         This is accomplished by redisplaying
  2475.         the button several times, alternating between active and
  2476.         normal colors. At the end of the flash the button is left
  2477.         in the same normal/active state as when the command was
  2478.         invoked. This command is ignored if the button's state is
  2479.         disabled.
  2480.         """
  2481.         self.tk.call(self._w, 'flash')
  2482.  
  2483.     
  2484.     def invoke(self):
  2485.         """Invoke the command associated with the button.
  2486.  
  2487.         The return value is the return value from the command,
  2488.         or an empty string if there is no command associated with
  2489.         the button. This command is ignored if the button's state
  2490.         is disabled.
  2491.         """
  2492.         return self.tk.call(self._w, 'invoke')
  2493.  
  2494.  
  2495.  
  2496. def AtEnd():
  2497.     return 'end'
  2498.  
  2499.  
  2500. def AtInsert(*args):
  2501.     s = 'insert'
  2502.     for a in args:
  2503.         if a:
  2504.             s = s + ' ' + a
  2505.             continue
  2506.     
  2507.     return s
  2508.  
  2509.  
  2510. def AtSelFirst():
  2511.     return 'sel.first'
  2512.  
  2513.  
  2514. def AtSelLast():
  2515.     return 'sel.last'
  2516.  
  2517.  
  2518. def At(x, y = None):
  2519.     if y is None:
  2520.         return '@%r' % (x,)
  2521.     return '@%r,%r' % (x, y)
  2522.  
  2523.  
  2524. class Canvas(Widget):
  2525.     '''Canvas widget to display graphical elements like lines or text.'''
  2526.     
  2527.     def __init__(self, master = None, cnf = { }, **kw):
  2528.         '''Construct a canvas widget with the parent MASTER.
  2529.  
  2530.         Valid resource names: background, bd, bg, borderwidth, closeenough,
  2531.         confine, cursor, height, highlightbackground, highlightcolor,
  2532.         highlightthickness, insertbackground, insertborderwidth,
  2533.         insertofftime, insertontime, insertwidth, offset, relief,
  2534.         scrollregion, selectbackground, selectborderwidth, selectforeground,
  2535.         state, takefocus, width, xscrollcommand, xscrollincrement,
  2536.         yscrollcommand, yscrollincrement.'''
  2537.         Widget.__init__(self, master, 'canvas', cnf, kw)
  2538.  
  2539.     
  2540.     def addtag(self, *args):
  2541.         '''Internal function.'''
  2542.         self.tk.call((self._w, 'addtag') + args)
  2543.  
  2544.     
  2545.     def addtag_above(self, newtag, tagOrId):
  2546.         '''Add tag NEWTAG to all items above TAGORID.'''
  2547.         self.addtag(newtag, 'above', tagOrId)
  2548.  
  2549.     
  2550.     def addtag_all(self, newtag):
  2551.         '''Add tag NEWTAG to all items.'''
  2552.         self.addtag(newtag, 'all')
  2553.  
  2554.     
  2555.     def addtag_below(self, newtag, tagOrId):
  2556.         '''Add tag NEWTAG to all items below TAGORID.'''
  2557.         self.addtag(newtag, 'below', tagOrId)
  2558.  
  2559.     
  2560.     def addtag_closest(self, newtag, x, y, halo = None, start = None):
  2561.         '''Add tag NEWTAG to item which is closest to pixel at X, Y.
  2562.         If several match take the top-most.
  2563.         All items closer than HALO are considered overlapping (all are
  2564.         closests). If START is specified the next below this tag is taken.'''
  2565.         self.addtag(newtag, 'closest', x, y, halo, start)
  2566.  
  2567.     
  2568.     def addtag_enclosed(self, newtag, x1, y1, x2, y2):
  2569.         '''Add tag NEWTAG to all items in the rectangle defined
  2570.         by X1,Y1,X2,Y2.'''
  2571.         self.addtag(newtag, 'enclosed', x1, y1, x2, y2)
  2572.  
  2573.     
  2574.     def addtag_overlapping(self, newtag, x1, y1, x2, y2):
  2575.         '''Add tag NEWTAG to all items which overlap the rectangle
  2576.         defined by X1,Y1,X2,Y2.'''
  2577.         self.addtag(newtag, 'overlapping', x1, y1, x2, y2)
  2578.  
  2579.     
  2580.     def addtag_withtag(self, newtag, tagOrId):
  2581.         '''Add tag NEWTAG to all items with TAGORID.'''
  2582.         self.addtag(newtag, 'withtag', tagOrId)
  2583.  
  2584.     
  2585.     def bbox(self, *args):
  2586.         '''Return a tuple of X1,Y1,X2,Y2 coordinates for a rectangle
  2587.         which encloses all items with tags specified as arguments.'''
  2588.         if not self._getints(self.tk.call((self._w, 'bbox') + args)):
  2589.             pass
  2590.  
  2591.     
  2592.     def tag_unbind(self, tagOrId, sequence, funcid = None):
  2593.         '''Unbind for all items with TAGORID for event SEQUENCE  the
  2594.         function identified with FUNCID.'''
  2595.         self.tk.call(self._w, 'bind', tagOrId, sequence, '')
  2596.         if funcid:
  2597.             self.deletecommand(funcid)
  2598.         
  2599.  
  2600.     
  2601.     def tag_bind(self, tagOrId, sequence = None, func = None, add = None):
  2602.         '''Bind to all items with TAGORID at event SEQUENCE a call to function FUNC.
  2603.  
  2604.         An additional boolean parameter ADD specifies whether FUNC will be
  2605.         called additionally to the other bound function or whether it will
  2606.         replace the previous function. See bind for the return value.'''
  2607.         return self._bind((self._w, 'bind', tagOrId), sequence, func, add)
  2608.  
  2609.     
  2610.     def canvasx(self, screenx, gridspacing = None):
  2611.         '''Return the canvas x coordinate of pixel position SCREENX rounded
  2612.         to nearest multiple of GRIDSPACING units.'''
  2613.         return getdouble(self.tk.call(self._w, 'canvasx', screenx, gridspacing))
  2614.  
  2615.     
  2616.     def canvasy(self, screeny, gridspacing = None):
  2617.         '''Return the canvas y coordinate of pixel position SCREENY rounded
  2618.         to nearest multiple of GRIDSPACING units.'''
  2619.         return getdouble(self.tk.call(self._w, 'canvasy', screeny, gridspacing))
  2620.  
  2621.     
  2622.     def coords(self, *args):
  2623.         '''Return a list of coordinates for the item given in ARGS.'''
  2624.         return map(getdouble, self.tk.splitlist(self.tk.call((self._w, 'coords') + args)))
  2625.  
  2626.     
  2627.     def _create(self, itemType, args, kw):
  2628.         '''Internal function.'''
  2629.         args = _flatten(args)
  2630.         cnf = args[-1]
  2631.         if type(cnf) in (DictionaryType, TupleType):
  2632.             args = args[:-1]
  2633.         else:
  2634.             cnf = { }
  2635.         return getint(self.tk.call(self._w, 'create', itemType, *args + self._options(cnf, kw)))
  2636.  
  2637.     
  2638.     def create_arc(self, *args, **kw):
  2639.         '''Create arc shaped region with coordinates x1,y1,x2,y2.'''
  2640.         return self._create('arc', args, kw)
  2641.  
  2642.     
  2643.     def create_bitmap(self, *args, **kw):
  2644.         '''Create bitmap with coordinates x1,y1.'''
  2645.         return self._create('bitmap', args, kw)
  2646.  
  2647.     
  2648.     def create_image(self, *args, **kw):
  2649.         '''Create image item with coordinates x1,y1.'''
  2650.         return self._create('image', args, kw)
  2651.  
  2652.     
  2653.     def create_line(self, *args, **kw):
  2654.         '''Create line with coordinates x1,y1,...,xn,yn.'''
  2655.         return self._create('line', args, kw)
  2656.  
  2657.     
  2658.     def create_oval(self, *args, **kw):
  2659.         '''Create oval with coordinates x1,y1,x2,y2.'''
  2660.         return self._create('oval', args, kw)
  2661.  
  2662.     
  2663.     def create_polygon(self, *args, **kw):
  2664.         '''Create polygon with coordinates x1,y1,...,xn,yn.'''
  2665.         return self._create('polygon', args, kw)
  2666.  
  2667.     
  2668.     def create_rectangle(self, *args, **kw):
  2669.         '''Create rectangle with coordinates x1,y1,x2,y2.'''
  2670.         return self._create('rectangle', args, kw)
  2671.  
  2672.     
  2673.     def create_text(self, *args, **kw):
  2674.         '''Create text with coordinates x1,y1.'''
  2675.         return self._create('text', args, kw)
  2676.  
  2677.     
  2678.     def create_window(self, *args, **kw):
  2679.         '''Create window with coordinates x1,y1,x2,y2.'''
  2680.         return self._create('window', args, kw)
  2681.  
  2682.     
  2683.     def dchars(self, *args):
  2684.         '''Delete characters of text items identified by tag or id in ARGS (possibly
  2685.         several times) from FIRST to LAST character (including).'''
  2686.         self.tk.call((self._w, 'dchars') + args)
  2687.  
  2688.     
  2689.     def delete(self, *args):
  2690.         '''Delete items identified by all tag or ids contained in ARGS.'''
  2691.         self.tk.call((self._w, 'delete') + args)
  2692.  
  2693.     
  2694.     def dtag(self, *args):
  2695.         '''Delete tag or id given as last arguments in ARGS from items
  2696.         identified by first argument in ARGS.'''
  2697.         self.tk.call((self._w, 'dtag') + args)
  2698.  
  2699.     
  2700.     def find(self, *args):
  2701.         '''Internal function.'''
  2702.         if not self._getints(self.tk.call((self._w, 'find') + args)):
  2703.             pass
  2704.         return ()
  2705.  
  2706.     
  2707.     def find_above(self, tagOrId):
  2708.         '''Return items above TAGORID.'''
  2709.         return self.find('above', tagOrId)
  2710.  
  2711.     
  2712.     def find_all(self):
  2713.         '''Return all items.'''
  2714.         return self.find('all')
  2715.  
  2716.     
  2717.     def find_below(self, tagOrId):
  2718.         '''Return all items below TAGORID.'''
  2719.         return self.find('below', tagOrId)
  2720.  
  2721.     
  2722.     def find_closest(self, x, y, halo = None, start = None):
  2723.         '''Return item which is closest to pixel at X, Y.
  2724.         If several match take the top-most.
  2725.         All items closer than HALO are considered overlapping (all are
  2726.         closests). If START is specified the next below this tag is taken.'''
  2727.         return self.find('closest', x, y, halo, start)
  2728.  
  2729.     
  2730.     def find_enclosed(self, x1, y1, x2, y2):
  2731.         '''Return all items in rectangle defined
  2732.         by X1,Y1,X2,Y2.'''
  2733.         return self.find('enclosed', x1, y1, x2, y2)
  2734.  
  2735.     
  2736.     def find_overlapping(self, x1, y1, x2, y2):
  2737.         '''Return all items which overlap the rectangle
  2738.         defined by X1,Y1,X2,Y2.'''
  2739.         return self.find('overlapping', x1, y1, x2, y2)
  2740.  
  2741.     
  2742.     def find_withtag(self, tagOrId):
  2743.         '''Return all items with TAGORID.'''
  2744.         return self.find('withtag', tagOrId)
  2745.  
  2746.     
  2747.     def focus(self, *args):
  2748.         '''Set focus to the first item specified in ARGS.'''
  2749.         return self.tk.call((self._w, 'focus') + args)
  2750.  
  2751.     
  2752.     def gettags(self, *args):
  2753.         '''Return tags associated with the first item specified in ARGS.'''
  2754.         return self.tk.splitlist(self.tk.call((self._w, 'gettags') + args))
  2755.  
  2756.     
  2757.     def icursor(self, *args):
  2758.         '''Set cursor at position POS in the item identified by TAGORID.
  2759.         In ARGS TAGORID must be first.'''
  2760.         self.tk.call((self._w, 'icursor') + args)
  2761.  
  2762.     
  2763.     def index(self, *args):
  2764.         '''Return position of cursor as integer in item specified in ARGS.'''
  2765.         return getint(self.tk.call((self._w, 'index') + args))
  2766.  
  2767.     
  2768.     def insert(self, *args):
  2769.         '''Insert TEXT in item TAGORID at position POS. ARGS must
  2770.         be TAGORID POS TEXT.'''
  2771.         self.tk.call((self._w, 'insert') + args)
  2772.  
  2773.     
  2774.     def itemcget(self, tagOrId, option):
  2775.         '''Return the resource value for an OPTION for item TAGORID.'''
  2776.         return self.tk.call((self._w, 'itemcget') + (tagOrId, '-' + option))
  2777.  
  2778.     
  2779.     def itemconfigure(self, tagOrId, cnf = None, **kw):
  2780.         '''Configure resources of an item TAGORID.
  2781.  
  2782.         The values for resources are specified as keyword
  2783.         arguments. To get an overview about
  2784.         the allowed keyword arguments call the method without arguments.
  2785.         '''
  2786.         return self._configure(('itemconfigure', tagOrId), cnf, kw)
  2787.  
  2788.     itemconfig = itemconfigure
  2789.     
  2790.     def tag_lower(self, *args):
  2791.         '''Lower an item TAGORID given in ARGS
  2792.         (optional below another item).'''
  2793.         self.tk.call((self._w, 'lower') + args)
  2794.  
  2795.     lower = tag_lower
  2796.     
  2797.     def move(self, *args):
  2798.         '''Move an item TAGORID given in ARGS.'''
  2799.         self.tk.call((self._w, 'move') + args)
  2800.  
  2801.     
  2802.     def postscript(self, cnf = { }, **kw):
  2803.         '''Print the contents of the canvas to a postscript
  2804.         file. Valid options: colormap, colormode, file, fontmap,
  2805.         height, pageanchor, pageheight, pagewidth, pagex, pagey,
  2806.         rotate, witdh, x, y.'''
  2807.         return self.tk.call((self._w, 'postscript') + self._options(cnf, kw))
  2808.  
  2809.     
  2810.     def tag_raise(self, *args):
  2811.         '''Raise an item TAGORID given in ARGS
  2812.         (optional above another item).'''
  2813.         self.tk.call((self._w, 'raise') + args)
  2814.  
  2815.     lift = tkraise = tag_raise
  2816.     
  2817.     def scale(self, *args):
  2818.         '''Scale item TAGORID with XORIGIN, YORIGIN, XSCALE, YSCALE.'''
  2819.         self.tk.call((self._w, 'scale') + args)
  2820.  
  2821.     
  2822.     def scan_mark(self, x, y):
  2823.         '''Remember the current X, Y coordinates.'''
  2824.         self.tk.call(self._w, 'scan', 'mark', x, y)
  2825.  
  2826.     
  2827.     def scan_dragto(self, x, y, gain = 10):
  2828.         '''Adjust the view of the canvas to GAIN times the
  2829.         difference between X and Y and the coordinates given in
  2830.         scan_mark.'''
  2831.         self.tk.call(self._w, 'scan', 'dragto', x, y, gain)
  2832.  
  2833.     
  2834.     def select_adjust(self, tagOrId, index):
  2835.         '''Adjust the end of the selection near the cursor of an item TAGORID to index.'''
  2836.         self.tk.call(self._w, 'select', 'adjust', tagOrId, index)
  2837.  
  2838.     
  2839.     def select_clear(self):
  2840.         '''Clear the selection if it is in this widget.'''
  2841.         self.tk.call(self._w, 'select', 'clear')
  2842.  
  2843.     
  2844.     def select_from(self, tagOrId, index):
  2845.         '''Set the fixed end of a selection in item TAGORID to INDEX.'''
  2846.         self.tk.call(self._w, 'select', 'from', tagOrId, index)
  2847.  
  2848.     
  2849.     def select_item(self):
  2850.         '''Return the item which has the selection.'''
  2851.         if not self.tk.call(self._w, 'select', 'item'):
  2852.             pass
  2853.  
  2854.     
  2855.     def select_to(self, tagOrId, index):
  2856.         '''Set the variable end of a selection in item TAGORID to INDEX.'''
  2857.         self.tk.call(self._w, 'select', 'to', tagOrId, index)
  2858.  
  2859.     
  2860.     def type(self, tagOrId):
  2861.         '''Return the type of the item TAGORID.'''
  2862.         if not self.tk.call(self._w, 'type', tagOrId):
  2863.             pass
  2864.  
  2865.     
  2866.     def xview(self, *args):
  2867.         '''Query and change horizontal position of the view.'''
  2868.         if not args:
  2869.             return self._getdoubles(self.tk.call(self._w, 'xview'))
  2870.         self.tk.call((self._w, 'xview') + args)
  2871.  
  2872.     
  2873.     def xview_moveto(self, fraction):
  2874.         '''Adjusts the view in the window so that FRACTION of the
  2875.         total width of the canvas is off-screen to the left.'''
  2876.         self.tk.call(self._w, 'xview', 'moveto', fraction)
  2877.  
  2878.     
  2879.     def xview_scroll(self, number, what):
  2880.         '''Shift the x-view according to NUMBER which is measured in "units" or "pages" (WHAT).'''
  2881.         self.tk.call(self._w, 'xview', 'scroll', number, what)
  2882.  
  2883.     
  2884.     def yview(self, *args):
  2885.         '''Query and change vertical position of the view.'''
  2886.         if not args:
  2887.             return self._getdoubles(self.tk.call(self._w, 'yview'))
  2888.         self.tk.call((self._w, 'yview') + args)
  2889.  
  2890.     
  2891.     def yview_moveto(self, fraction):
  2892.         '''Adjusts the view in the window so that FRACTION of the
  2893.         total height of the canvas is off-screen to the top.'''
  2894.         self.tk.call(self._w, 'yview', 'moveto', fraction)
  2895.  
  2896.     
  2897.     def yview_scroll(self, number, what):
  2898.         '''Shift the y-view according to NUMBER which is measured in "units" or "pages" (WHAT).'''
  2899.         self.tk.call(self._w, 'yview', 'scroll', number, what)
  2900.  
  2901.  
  2902.  
  2903. class Checkbutton(Widget):
  2904.     '''Checkbutton widget which is either in on- or off-state.'''
  2905.     
  2906.     def __init__(self, master = None, cnf = { }, **kw):
  2907.         '''Construct a checkbutton widget with the parent MASTER.
  2908.  
  2909.         Valid resource names: activebackground, activeforeground, anchor,
  2910.         background, bd, bg, bitmap, borderwidth, command, cursor,
  2911.         disabledforeground, fg, font, foreground, height,
  2912.         highlightbackground, highlightcolor, highlightthickness, image,
  2913.         indicatoron, justify, offvalue, onvalue, padx, pady, relief,
  2914.         selectcolor, selectimage, state, takefocus, text, textvariable,
  2915.         underline, variable, width, wraplength.'''
  2916.         Widget.__init__(self, master, 'checkbutton', cnf, kw)
  2917.  
  2918.     
  2919.     def deselect(self):
  2920.         '''Put the button in off-state.'''
  2921.         self.tk.call(self._w, 'deselect')
  2922.  
  2923.     
  2924.     def flash(self):
  2925.         '''Flash the button.'''
  2926.         self.tk.call(self._w, 'flash')
  2927.  
  2928.     
  2929.     def invoke(self):
  2930.         '''Toggle the button and invoke a command if given as resource.'''
  2931.         return self.tk.call(self._w, 'invoke')
  2932.  
  2933.     
  2934.     def select(self):
  2935.         '''Put the button in on-state.'''
  2936.         self.tk.call(self._w, 'select')
  2937.  
  2938.     
  2939.     def toggle(self):
  2940.         '''Toggle the button.'''
  2941.         self.tk.call(self._w, 'toggle')
  2942.  
  2943.  
  2944.  
  2945. class Entry(Widget):
  2946.     '''Entry widget which allows to display simple text.'''
  2947.     
  2948.     def __init__(self, master = None, cnf = { }, **kw):
  2949.         '''Construct an entry widget with the parent MASTER.
  2950.  
  2951.         Valid resource names: background, bd, bg, borderwidth, cursor,
  2952.         exportselection, fg, font, foreground, highlightbackground,
  2953.         highlightcolor, highlightthickness, insertbackground,
  2954.         insertborderwidth, insertofftime, insertontime, insertwidth,
  2955.         invalidcommand, invcmd, justify, relief, selectbackground,
  2956.         selectborderwidth, selectforeground, show, state, takefocus,
  2957.         textvariable, validate, validatecommand, vcmd, width,
  2958.         xscrollcommand.'''
  2959.         Widget.__init__(self, master, 'entry', cnf, kw)
  2960.  
  2961.     
  2962.     def delete(self, first, last = None):
  2963.         '''Delete text from FIRST to LAST (not included).'''
  2964.         self.tk.call(self._w, 'delete', first, last)
  2965.  
  2966.     
  2967.     def get(self):
  2968.         '''Return the text.'''
  2969.         return self.tk.call(self._w, 'get')
  2970.  
  2971.     
  2972.     def icursor(self, index):
  2973.         '''Insert cursor at INDEX.'''
  2974.         self.tk.call(self._w, 'icursor', index)
  2975.  
  2976.     
  2977.     def index(self, index):
  2978.         '''Return position of cursor.'''
  2979.         return getint(self.tk.call(self._w, 'index', index))
  2980.  
  2981.     
  2982.     def insert(self, index, string):
  2983.         '''Insert STRING at INDEX.'''
  2984.         self.tk.call(self._w, 'insert', index, string)
  2985.  
  2986.     
  2987.     def scan_mark(self, x):
  2988.         '''Remember the current X, Y coordinates.'''
  2989.         self.tk.call(self._w, 'scan', 'mark', x)
  2990.  
  2991.     
  2992.     def scan_dragto(self, x):
  2993.         '''Adjust the view of the canvas to 10 times the
  2994.         difference between X and Y and the coordinates given in
  2995.         scan_mark.'''
  2996.         self.tk.call(self._w, 'scan', 'dragto', x)
  2997.  
  2998.     
  2999.     def selection_adjust(self, index):
  3000.         '''Adjust the end of the selection near the cursor to INDEX.'''
  3001.         self.tk.call(self._w, 'selection', 'adjust', index)
  3002.  
  3003.     select_adjust = selection_adjust
  3004.     
  3005.     def selection_clear(self):
  3006.         '''Clear the selection if it is in this widget.'''
  3007.         self.tk.call(self._w, 'selection', 'clear')
  3008.  
  3009.     select_clear = selection_clear
  3010.     
  3011.     def selection_from(self, index):
  3012.         '''Set the fixed end of a selection to INDEX.'''
  3013.         self.tk.call(self._w, 'selection', 'from', index)
  3014.  
  3015.     select_from = selection_from
  3016.     
  3017.     def selection_present(self):
  3018.         '''Return whether the widget has the selection.'''
  3019.         return self.tk.getboolean(self.tk.call(self._w, 'selection', 'present'))
  3020.  
  3021.     select_present = selection_present
  3022.     
  3023.     def selection_range(self, start, end):
  3024.         '''Set the selection from START to END (not included).'''
  3025.         self.tk.call(self._w, 'selection', 'range', start, end)
  3026.  
  3027.     select_range = selection_range
  3028.     
  3029.     def selection_to(self, index):
  3030.         '''Set the variable end of a selection to INDEX.'''
  3031.         self.tk.call(self._w, 'selection', 'to', index)
  3032.  
  3033.     select_to = selection_to
  3034.     
  3035.     def xview(self, index):
  3036.         '''Query and change horizontal position of the view.'''
  3037.         self.tk.call(self._w, 'xview', index)
  3038.  
  3039.     
  3040.     def xview_moveto(self, fraction):
  3041.         '''Adjust the view in the window so that FRACTION of the
  3042.         total width of the entry is off-screen to the left.'''
  3043.         self.tk.call(self._w, 'xview', 'moveto', fraction)
  3044.  
  3045.     
  3046.     def xview_scroll(self, number, what):
  3047.         '''Shift the x-view according to NUMBER which is measured in "units" or "pages" (WHAT).'''
  3048.         self.tk.call(self._w, 'xview', 'scroll', number, what)
  3049.  
  3050.  
  3051.  
  3052. class Frame(Widget):
  3053.     '''Frame widget which may contain other widgets and can have a 3D border.'''
  3054.     
  3055.     def __init__(self, master = None, cnf = { }, **kw):
  3056.         '''Construct a frame widget with the parent MASTER.
  3057.  
  3058.         Valid resource names: background, bd, bg, borderwidth, class,
  3059.         colormap, container, cursor, height, highlightbackground,
  3060.         highlightcolor, highlightthickness, relief, takefocus, visual, width.'''
  3061.         cnf = _cnfmerge((cnf, kw))
  3062.         extra = ()
  3063.         if cnf.has_key('class_'):
  3064.             extra = ('-class', cnf['class_'])
  3065.             del cnf['class_']
  3066.         elif cnf.has_key('class'):
  3067.             extra = ('-class', cnf['class'])
  3068.             del cnf['class']
  3069.         
  3070.         Widget.__init__(self, master, 'frame', cnf, { }, extra)
  3071.  
  3072.  
  3073.  
  3074. class Label(Widget):
  3075.     '''Label widget which can display text and bitmaps.'''
  3076.     
  3077.     def __init__(self, master = None, cnf = { }, **kw):
  3078.         '''Construct a label widget with the parent MASTER.
  3079.  
  3080.         STANDARD OPTIONS
  3081.  
  3082.             activebackground, activeforeground, anchor,
  3083.             background, bitmap, borderwidth, cursor,
  3084.             disabledforeground, font, foreground,
  3085.             highlightbackground, highlightcolor,
  3086.             highlightthickness, image, justify,
  3087.             padx, pady, relief, takefocus, text,
  3088.             textvariable, underline, wraplength
  3089.  
  3090.         WIDGET-SPECIFIC OPTIONS
  3091.  
  3092.             height, state, width
  3093.  
  3094.         '''
  3095.         Widget.__init__(self, master, 'label', cnf, kw)
  3096.  
  3097.  
  3098.  
  3099. class Listbox(Widget):
  3100.     '''Listbox widget which can display a list of strings.'''
  3101.     
  3102.     def __init__(self, master = None, cnf = { }, **kw):
  3103.         '''Construct a listbox widget with the parent MASTER.
  3104.  
  3105.         Valid resource names: background, bd, bg, borderwidth, cursor,
  3106.         exportselection, fg, font, foreground, height, highlightbackground,
  3107.         highlightcolor, highlightthickness, relief, selectbackground,
  3108.         selectborderwidth, selectforeground, selectmode, setgrid, takefocus,
  3109.         width, xscrollcommand, yscrollcommand, listvariable.'''
  3110.         Widget.__init__(self, master, 'listbox', cnf, kw)
  3111.  
  3112.     
  3113.     def activate(self, index):
  3114.         '''Activate item identified by INDEX.'''
  3115.         self.tk.call(self._w, 'activate', index)
  3116.  
  3117.     
  3118.     def bbox(self, *args):
  3119.         '''Return a tuple of X1,Y1,X2,Y2 coordinates for a rectangle
  3120.         which encloses the item identified by index in ARGS.'''
  3121.         if not self._getints(self.tk.call((self._w, 'bbox') + args)):
  3122.             pass
  3123.  
  3124.     
  3125.     def curselection(self):
  3126.         '''Return list of indices of currently selected item.'''
  3127.         return self.tk.splitlist(self.tk.call(self._w, 'curselection'))
  3128.  
  3129.     
  3130.     def delete(self, first, last = None):
  3131.         '''Delete items from FIRST to LAST (not included).'''
  3132.         self.tk.call(self._w, 'delete', first, last)
  3133.  
  3134.     
  3135.     def get(self, first, last = None):
  3136.         '''Get list of items from FIRST to LAST (not included).'''
  3137.         if last:
  3138.             return self.tk.splitlist(self.tk.call(self._w, 'get', first, last))
  3139.         return self.tk.call(self._w, 'get', first)
  3140.  
  3141.     
  3142.     def index(self, index):
  3143.         '''Return index of item identified with INDEX.'''
  3144.         i = self.tk.call(self._w, 'index', index)
  3145.         if i == 'none':
  3146.             return None
  3147.         return getint(i)
  3148.  
  3149.     
  3150.     def insert(self, index, *elements):
  3151.         '''Insert ELEMENTS at INDEX.'''
  3152.         self.tk.call((self._w, 'insert', index) + elements)
  3153.  
  3154.     
  3155.     def nearest(self, y):
  3156.         '''Get index of item which is nearest to y coordinate Y.'''
  3157.         return getint(self.tk.call(self._w, 'nearest', y))
  3158.  
  3159.     
  3160.     def scan_mark(self, x, y):
  3161.         '''Remember the current X, Y coordinates.'''
  3162.         self.tk.call(self._w, 'scan', 'mark', x, y)
  3163.  
  3164.     
  3165.     def scan_dragto(self, x, y):
  3166.         '''Adjust the view of the listbox to 10 times the
  3167.         difference between X and Y and the coordinates given in
  3168.         scan_mark.'''
  3169.         self.tk.call(self._w, 'scan', 'dragto', x, y)
  3170.  
  3171.     
  3172.     def see(self, index):
  3173.         '''Scroll such that INDEX is visible.'''
  3174.         self.tk.call(self._w, 'see', index)
  3175.  
  3176.     
  3177.     def selection_anchor(self, index):
  3178.         '''Set the fixed end oft the selection to INDEX.'''
  3179.         self.tk.call(self._w, 'selection', 'anchor', index)
  3180.  
  3181.     select_anchor = selection_anchor
  3182.     
  3183.     def selection_clear(self, first, last = None):
  3184.         '''Clear the selection from FIRST to LAST (not included).'''
  3185.         self.tk.call(self._w, 'selection', 'clear', first, last)
  3186.  
  3187.     select_clear = selection_clear
  3188.     
  3189.     def selection_includes(self, index):
  3190.         '''Return 1 if INDEX is part of the selection.'''
  3191.         return self.tk.getboolean(self.tk.call(self._w, 'selection', 'includes', index))
  3192.  
  3193.     select_includes = selection_includes
  3194.     
  3195.     def selection_set(self, first, last = None):
  3196.         '''Set the selection from FIRST to LAST (not included) without
  3197.         changing the currently selected elements.'''
  3198.         self.tk.call(self._w, 'selection', 'set', first, last)
  3199.  
  3200.     select_set = selection_set
  3201.     
  3202.     def size(self):
  3203.         '''Return the number of elements in the listbox.'''
  3204.         return getint(self.tk.call(self._w, 'size'))
  3205.  
  3206.     
  3207.     def xview(self, *what):
  3208.         '''Query and change horizontal position of the view.'''
  3209.         if not what:
  3210.             return self._getdoubles(self.tk.call(self._w, 'xview'))
  3211.         self.tk.call((self._w, 'xview') + what)
  3212.  
  3213.     
  3214.     def xview_moveto(self, fraction):
  3215.         '''Adjust the view in the window so that FRACTION of the
  3216.         total width of the entry is off-screen to the left.'''
  3217.         self.tk.call(self._w, 'xview', 'moveto', fraction)
  3218.  
  3219.     
  3220.     def xview_scroll(self, number, what):
  3221.         '''Shift the x-view according to NUMBER which is measured in "units" or "pages" (WHAT).'''
  3222.         self.tk.call(self._w, 'xview', 'scroll', number, what)
  3223.  
  3224.     
  3225.     def yview(self, *what):
  3226.         '''Query and change vertical position of the view.'''
  3227.         if not what:
  3228.             return self._getdoubles(self.tk.call(self._w, 'yview'))
  3229.         self.tk.call((self._w, 'yview') + what)
  3230.  
  3231.     
  3232.     def yview_moveto(self, fraction):
  3233.         '''Adjust the view in the window so that FRACTION of the
  3234.         total width of the entry is off-screen to the top.'''
  3235.         self.tk.call(self._w, 'yview', 'moveto', fraction)
  3236.  
  3237.     
  3238.     def yview_scroll(self, number, what):
  3239.         '''Shift the y-view according to NUMBER which is measured in "units" or "pages" (WHAT).'''
  3240.         self.tk.call(self._w, 'yview', 'scroll', number, what)
  3241.  
  3242.     
  3243.     def itemcget(self, index, option):
  3244.         '''Return the resource value for an ITEM and an OPTION.'''
  3245.         return self.tk.call((self._w, 'itemcget') + (index, '-' + option))
  3246.  
  3247.     
  3248.     def itemconfigure(self, index, cnf = None, **kw):
  3249.         '''Configure resources of an ITEM.
  3250.  
  3251.         The values for resources are specified as keyword arguments.
  3252.         To get an overview about the allowed keyword arguments
  3253.         call the method without arguments.
  3254.         Valid resource names: background, bg, foreground, fg,
  3255.         selectbackground, selectforeground.'''
  3256.         return self._configure(('itemconfigure', index), cnf, kw)
  3257.  
  3258.     itemconfig = itemconfigure
  3259.  
  3260.  
  3261. class Menu(Widget):
  3262.     '''Menu widget which allows to display menu bars, pull-down menus and pop-up menus.'''
  3263.     
  3264.     def __init__(self, master = None, cnf = { }, **kw):
  3265.         '''Construct menu widget with the parent MASTER.
  3266.  
  3267.         Valid resource names: activebackground, activeborderwidth,
  3268.         activeforeground, background, bd, bg, borderwidth, cursor,
  3269.         disabledforeground, fg, font, foreground, postcommand, relief,
  3270.         selectcolor, takefocus, tearoff, tearoffcommand, title, type.'''
  3271.         Widget.__init__(self, master, 'menu', cnf, kw)
  3272.  
  3273.     
  3274.     def tk_bindForTraversal(self):
  3275.         pass
  3276.  
  3277.     
  3278.     def tk_mbPost(self):
  3279.         self.tk.call('tk_mbPost', self._w)
  3280.  
  3281.     
  3282.     def tk_mbUnpost(self):
  3283.         self.tk.call('tk_mbUnpost')
  3284.  
  3285.     
  3286.     def tk_traverseToMenu(self, char):
  3287.         self.tk.call('tk_traverseToMenu', self._w, char)
  3288.  
  3289.     
  3290.     def tk_traverseWithinMenu(self, char):
  3291.         self.tk.call('tk_traverseWithinMenu', self._w, char)
  3292.  
  3293.     
  3294.     def tk_getMenuButtons(self):
  3295.         return self.tk.call('tk_getMenuButtons', self._w)
  3296.  
  3297.     
  3298.     def tk_nextMenu(self, count):
  3299.         self.tk.call('tk_nextMenu', count)
  3300.  
  3301.     
  3302.     def tk_nextMenuEntry(self, count):
  3303.         self.tk.call('tk_nextMenuEntry', count)
  3304.  
  3305.     
  3306.     def tk_invokeMenu(self):
  3307.         self.tk.call('tk_invokeMenu', self._w)
  3308.  
  3309.     
  3310.     def tk_firstMenu(self):
  3311.         self.tk.call('tk_firstMenu', self._w)
  3312.  
  3313.     
  3314.     def tk_mbButtonDown(self):
  3315.         self.tk.call('tk_mbButtonDown', self._w)
  3316.  
  3317.     
  3318.     def tk_popup(self, x, y, entry = ''):
  3319.         '''Post the menu at position X,Y with entry ENTRY.'''
  3320.         self.tk.call('tk_popup', self._w, x, y, entry)
  3321.  
  3322.     
  3323.     def activate(self, index):
  3324.         '''Activate entry at INDEX.'''
  3325.         self.tk.call(self._w, 'activate', index)
  3326.  
  3327.     
  3328.     def add(self, itemType, cnf = { }, **kw):
  3329.         '''Internal function.'''
  3330.         self.tk.call((self._w, 'add', itemType) + self._options(cnf, kw))
  3331.  
  3332.     
  3333.     def add_cascade(self, cnf = { }, **kw):
  3334.         '''Add hierarchical menu item.'''
  3335.         if not cnf:
  3336.             pass
  3337.         self.add('cascade', kw)
  3338.  
  3339.     
  3340.     def add_checkbutton(self, cnf = { }, **kw):
  3341.         '''Add checkbutton menu item.'''
  3342.         if not cnf:
  3343.             pass
  3344.         self.add('checkbutton', kw)
  3345.  
  3346.     
  3347.     def add_command(self, cnf = { }, **kw):
  3348.         '''Add command menu item.'''
  3349.         if not cnf:
  3350.             pass
  3351.         self.add('command', kw)
  3352.  
  3353.     
  3354.     def add_radiobutton(self, cnf = { }, **kw):
  3355.         '''Addd radio menu item.'''
  3356.         if not cnf:
  3357.             pass
  3358.         self.add('radiobutton', kw)
  3359.  
  3360.     
  3361.     def add_separator(self, cnf = { }, **kw):
  3362.         '''Add separator.'''
  3363.         if not cnf:
  3364.             pass
  3365.         self.add('separator', kw)
  3366.  
  3367.     
  3368.     def insert(self, index, itemType, cnf = { }, **kw):
  3369.         '''Internal function.'''
  3370.         self.tk.call((self._w, 'insert', index, itemType) + self._options(cnf, kw))
  3371.  
  3372.     
  3373.     def insert_cascade(self, index, cnf = { }, **kw):
  3374.         '''Add hierarchical menu item at INDEX.'''
  3375.         if not cnf:
  3376.             pass
  3377.         self.insert(index, 'cascade', kw)
  3378.  
  3379.     
  3380.     def insert_checkbutton(self, index, cnf = { }, **kw):
  3381.         '''Add checkbutton menu item at INDEX.'''
  3382.         if not cnf:
  3383.             pass
  3384.         self.insert(index, 'checkbutton', kw)
  3385.  
  3386.     
  3387.     def insert_command(self, index, cnf = { }, **kw):
  3388.         '''Add command menu item at INDEX.'''
  3389.         if not cnf:
  3390.             pass
  3391.         self.insert(index, 'command', kw)
  3392.  
  3393.     
  3394.     def insert_radiobutton(self, index, cnf = { }, **kw):
  3395.         '''Addd radio menu item at INDEX.'''
  3396.         if not cnf:
  3397.             pass
  3398.         self.insert(index, 'radiobutton', kw)
  3399.  
  3400.     
  3401.     def insert_separator(self, index, cnf = { }, **kw):
  3402.         '''Add separator at INDEX.'''
  3403.         if not cnf:
  3404.             pass
  3405.         self.insert(index, 'separator', kw)
  3406.  
  3407.     
  3408.     def delete(self, index1, index2 = None):
  3409.         '''Delete menu items between INDEX1 and INDEX2 (included).'''
  3410.         if index2 is None:
  3411.             index2 = index1
  3412.         
  3413.         num_index1 = self.index(index1)
  3414.         num_index2 = self.index(index2)
  3415.         if num_index1 is None or num_index2 is None:
  3416.             (num_index1, num_index2) = (0, -1)
  3417.         
  3418.         for i in range(num_index1, num_index2 + 1):
  3419.             if 'command' in self.entryconfig(i):
  3420.                 c = str(self.entrycget(i, 'command'))
  3421.                 if c:
  3422.                     self.deletecommand(c)
  3423.                 
  3424.             c
  3425.         
  3426.         self.tk.call(self._w, 'delete', index1, index2)
  3427.  
  3428.     
  3429.     def entrycget(self, index, option):
  3430.         '''Return the resource value of an menu item for OPTION at INDEX.'''
  3431.         return self.tk.call(self._w, 'entrycget', index, '-' + option)
  3432.  
  3433.     
  3434.     def entryconfigure(self, index, cnf = None, **kw):
  3435.         '''Configure a menu item at INDEX.'''
  3436.         return self._configure(('entryconfigure', index), cnf, kw)
  3437.  
  3438.     entryconfig = entryconfigure
  3439.     
  3440.     def index(self, index):
  3441.         '''Return the index of a menu item identified by INDEX.'''
  3442.         i = self.tk.call(self._w, 'index', index)
  3443.         if i == 'none':
  3444.             return None
  3445.         return getint(i)
  3446.  
  3447.     
  3448.     def invoke(self, index):
  3449.         '''Invoke a menu item identified by INDEX and execute
  3450.         the associated command.'''
  3451.         return self.tk.call(self._w, 'invoke', index)
  3452.  
  3453.     
  3454.     def post(self, x, y):
  3455.         '''Display a menu at position X,Y.'''
  3456.         self.tk.call(self._w, 'post', x, y)
  3457.  
  3458.     
  3459.     def type(self, index):
  3460.         '''Return the type of the menu item at INDEX.'''
  3461.         return self.tk.call(self._w, 'type', index)
  3462.  
  3463.     
  3464.     def unpost(self):
  3465.         '''Unmap a menu.'''
  3466.         self.tk.call(self._w, 'unpost')
  3467.  
  3468.     
  3469.     def yposition(self, index):
  3470.         '''Return the y-position of the topmost pixel of the menu item at INDEX.'''
  3471.         return getint(self.tk.call(self._w, 'yposition', index))
  3472.  
  3473.  
  3474.  
  3475. class Menubutton(Widget):
  3476.     '''Menubutton widget, obsolete since Tk8.0.'''
  3477.     
  3478.     def __init__(self, master = None, cnf = { }, **kw):
  3479.         Widget.__init__(self, master, 'menubutton', cnf, kw)
  3480.  
  3481.  
  3482.  
  3483. class Message(Widget):
  3484.     '''Message widget to display multiline text. Obsolete since Label does it too.'''
  3485.     
  3486.     def __init__(self, master = None, cnf = { }, **kw):
  3487.         Widget.__init__(self, master, 'message', cnf, kw)
  3488.  
  3489.  
  3490.  
  3491. class Radiobutton(Widget):
  3492.     '''Radiobutton widget which shows only one of several buttons in on-state.'''
  3493.     
  3494.     def __init__(self, master = None, cnf = { }, **kw):
  3495.         '''Construct a radiobutton widget with the parent MASTER.
  3496.  
  3497.         Valid resource names: activebackground, activeforeground, anchor,
  3498.         background, bd, bg, bitmap, borderwidth, command, cursor,
  3499.         disabledforeground, fg, font, foreground, height,
  3500.         highlightbackground, highlightcolor, highlightthickness, image,
  3501.         indicatoron, justify, padx, pady, relief, selectcolor, selectimage,
  3502.         state, takefocus, text, textvariable, underline, value, variable,
  3503.         width, wraplength.'''
  3504.         Widget.__init__(self, master, 'radiobutton', cnf, kw)
  3505.  
  3506.     
  3507.     def deselect(self):
  3508.         '''Put the button in off-state.'''
  3509.         self.tk.call(self._w, 'deselect')
  3510.  
  3511.     
  3512.     def flash(self):
  3513.         '''Flash the button.'''
  3514.         self.tk.call(self._w, 'flash')
  3515.  
  3516.     
  3517.     def invoke(self):
  3518.         '''Toggle the button and invoke a command if given as resource.'''
  3519.         return self.tk.call(self._w, 'invoke')
  3520.  
  3521.     
  3522.     def select(self):
  3523.         '''Put the button in on-state.'''
  3524.         self.tk.call(self._w, 'select')
  3525.  
  3526.  
  3527.  
  3528. class Scale(Widget):
  3529.     '''Scale widget which can display a numerical scale.'''
  3530.     
  3531.     def __init__(self, master = None, cnf = { }, **kw):
  3532.         '''Construct a scale widget with the parent MASTER.
  3533.  
  3534.         Valid resource names: activebackground, background, bigincrement, bd,
  3535.         bg, borderwidth, command, cursor, digits, fg, font, foreground, from,
  3536.         highlightbackground, highlightcolor, highlightthickness, label,
  3537.         length, orient, relief, repeatdelay, repeatinterval, resolution,
  3538.         showvalue, sliderlength, sliderrelief, state, takefocus,
  3539.         tickinterval, to, troughcolor, variable, width.'''
  3540.         Widget.__init__(self, master, 'scale', cnf, kw)
  3541.  
  3542.     
  3543.     def get(self):
  3544.         '''Get the current value as integer or float.'''
  3545.         value = self.tk.call(self._w, 'get')
  3546.         
  3547.         try:
  3548.             return getint(value)
  3549.         except ValueError:
  3550.             return getdouble(value)
  3551.  
  3552.  
  3553.     
  3554.     def set(self, value):
  3555.         '''Set the value to VALUE.'''
  3556.         self.tk.call(self._w, 'set', value)
  3557.  
  3558.     
  3559.     def coords(self, value = None):
  3560.         '''Return a tuple (X,Y) of the point along the centerline of the
  3561.         trough that corresponds to VALUE or the current value if None is
  3562.         given.'''
  3563.         return self._getints(self.tk.call(self._w, 'coords', value))
  3564.  
  3565.     
  3566.     def identify(self, x, y):
  3567.         '''Return where the point X,Y lies. Valid return values are "slider",
  3568.         "though1" and "though2".'''
  3569.         return self.tk.call(self._w, 'identify', x, y)
  3570.  
  3571.  
  3572.  
  3573. class Scrollbar(Widget):
  3574.     '''Scrollbar widget which displays a slider at a certain position.'''
  3575.     
  3576.     def __init__(self, master = None, cnf = { }, **kw):
  3577.         '''Construct a scrollbar widget with the parent MASTER.
  3578.  
  3579.         Valid resource names: activebackground, activerelief,
  3580.         background, bd, bg, borderwidth, command, cursor,
  3581.         elementborderwidth, highlightbackground,
  3582.         highlightcolor, highlightthickness, jump, orient,
  3583.         relief, repeatdelay, repeatinterval, takefocus,
  3584.         troughcolor, width.'''
  3585.         Widget.__init__(self, master, 'scrollbar', cnf, kw)
  3586.  
  3587.     
  3588.     def activate(self, index):
  3589.         '''Display the element at INDEX with activebackground and activerelief.
  3590.         INDEX can be "arrow1","slider" or "arrow2".'''
  3591.         self.tk.call(self._w, 'activate', index)
  3592.  
  3593.     
  3594.     def delta(self, deltax, deltay):
  3595.         '''Return the fractional change of the scrollbar setting if it
  3596.         would be moved by DELTAX or DELTAY pixels.'''
  3597.         return getdouble(self.tk.call(self._w, 'delta', deltax, deltay))
  3598.  
  3599.     
  3600.     def fraction(self, x, y):
  3601.         '''Return the fractional value which corresponds to a slider
  3602.         position of X,Y.'''
  3603.         return getdouble(self.tk.call(self._w, 'fraction', x, y))
  3604.  
  3605.     
  3606.     def identify(self, x, y):
  3607.         '''Return the element under position X,Y as one of
  3608.         "arrow1","slider","arrow2" or "".'''
  3609.         return self.tk.call(self._w, 'identify', x, y)
  3610.  
  3611.     
  3612.     def get(self):
  3613.         '''Return the current fractional values (upper and lower end)
  3614.         of the slider position.'''
  3615.         return self._getdoubles(self.tk.call(self._w, 'get'))
  3616.  
  3617.     
  3618.     def set(self, *args):
  3619.         '''Set the fractional values of the slider position (upper and
  3620.         lower ends as value between 0 and 1).'''
  3621.         self.tk.call((self._w, 'set') + args)
  3622.  
  3623.  
  3624.  
  3625. class Text(Widget):
  3626.     '''Text widget which can display text in various forms.'''
  3627.     
  3628.     def __init__(self, master = None, cnf = { }, **kw):
  3629.         '''Construct a text widget with the parent MASTER.
  3630.  
  3631.         STANDARD OPTIONS
  3632.  
  3633.             background, borderwidth, cursor,
  3634.             exportselection, font, foreground,
  3635.             highlightbackground, highlightcolor,
  3636.             highlightthickness, insertbackground,
  3637.             insertborderwidth, insertofftime,
  3638.             insertontime, insertwidth, padx, pady,
  3639.             relief, selectbackground,
  3640.             selectborderwidth, selectforeground,
  3641.             setgrid, takefocus,
  3642.             xscrollcommand, yscrollcommand,
  3643.  
  3644.         WIDGET-SPECIFIC OPTIONS
  3645.  
  3646.             autoseparators, height, maxundo,
  3647.             spacing1, spacing2, spacing3,
  3648.             state, tabs, undo, width, wrap,
  3649.  
  3650.         '''
  3651.         Widget.__init__(self, master, 'text', cnf, kw)
  3652.  
  3653.     
  3654.     def bbox(self, *args):
  3655.         '''Return a tuple of (x,y,width,height) which gives the bounding
  3656.         box of the visible part of the character at the index in ARGS.'''
  3657.         if not self._getints(self.tk.call((self._w, 'bbox') + args)):
  3658.             pass
  3659.  
  3660.     
  3661.     def tk_textSelectTo(self, index):
  3662.         self.tk.call('tk_textSelectTo', self._w, index)
  3663.  
  3664.     
  3665.     def tk_textBackspace(self):
  3666.         self.tk.call('tk_textBackspace', self._w)
  3667.  
  3668.     
  3669.     def tk_textIndexCloser(self, a, b, c):
  3670.         self.tk.call('tk_textIndexCloser', self._w, a, b, c)
  3671.  
  3672.     
  3673.     def tk_textResetAnchor(self, index):
  3674.         self.tk.call('tk_textResetAnchor', self._w, index)
  3675.  
  3676.     
  3677.     def compare(self, index1, op, index2):
  3678.         '''Return whether between index INDEX1 and index INDEX2 the
  3679.         relation OP is satisfied. OP is one of <, <=, ==, >=, >, or !=.'''
  3680.         return self.tk.getboolean(self.tk.call(self._w, 'compare', index1, op, index2))
  3681.  
  3682.     
  3683.     def debug(self, boolean = None):
  3684.         '''Turn on the internal consistency checks of the B-Tree inside the text
  3685.         widget according to BOOLEAN.'''
  3686.         return self.tk.getboolean(self.tk.call(self._w, 'debug', boolean))
  3687.  
  3688.     
  3689.     def delete(self, index1, index2 = None):
  3690.         '''Delete the characters between INDEX1 and INDEX2 (not included).'''
  3691.         self.tk.call(self._w, 'delete', index1, index2)
  3692.  
  3693.     
  3694.     def dlineinfo(self, index):
  3695.         '''Return tuple (x,y,width,height,baseline) giving the bounding box
  3696.         and baseline position of the visible part of the line containing
  3697.         the character at INDEX.'''
  3698.         return self._getints(self.tk.call(self._w, 'dlineinfo', index))
  3699.  
  3700.     
  3701.     def dump(self, index1, index2 = None, command = None, **kw):
  3702.         """Return the contents of the widget between index1 and index2.
  3703.  
  3704.         The type of contents returned in filtered based on the keyword
  3705.         parameters; if 'all', 'image', 'mark', 'tag', 'text', or 'window' are
  3706.         given and true, then the corresponding items are returned. The result
  3707.         is a list of triples of the form (key, value, index). If none of the
  3708.         keywords are true then 'all' is used by default.
  3709.  
  3710.         If the 'command' argument is given, it is called once for each element
  3711.         of the list of triples, with the values of each triple serving as the
  3712.         arguments to the function. In this case the list is not returned."""
  3713.         args = []
  3714.         func_name = None
  3715.         result = None
  3716.         if not command:
  3717.             result = []
  3718.             
  3719.             def append_triple(key, value, index, result = result):
  3720.                 result.append((key, value, index))
  3721.  
  3722.             command = append_triple
  3723.         
  3724.         
  3725.         try:
  3726.             if not isinstance(command, str):
  3727.                 func_name = command = self._register(command)
  3728.             
  3729.             args += [
  3730.                 '-command',
  3731.                 command]
  3732.             for key in kw:
  3733.                 if kw[key]:
  3734.                     args.append('-' + key)
  3735.                     continue
  3736.             
  3737.             args.append(index1)
  3738.             if index2:
  3739.                 args.append(index2)
  3740.             
  3741.             self.tk.call(self._w, 'dump', *args)
  3742.             return result
  3743.         finally:
  3744.             if func_name:
  3745.                 self.deletecommand(func_name)
  3746.             
  3747.  
  3748.  
  3749.     
  3750.     def edit(self, *args):
  3751.         '''Internal method
  3752.  
  3753.         This method controls the undo mechanism and
  3754.         the modified flag. The exact behavior of the
  3755.         command depends on the option argument that
  3756.         follows the edit argument. The following forms
  3757.         of the command are currently supported:
  3758.  
  3759.         edit_modified, edit_redo, edit_reset, edit_separator
  3760.         and edit_undo
  3761.  
  3762.         '''
  3763.         return self.tk.call(self._w, 'edit', *args)
  3764.  
  3765.     
  3766.     def edit_modified(self, arg = None):
  3767.         '''Get or Set the modified flag
  3768.  
  3769.         If arg is not specified, returns the modified
  3770.         flag of the widget. The insert, delete, edit undo and
  3771.         edit redo commands or the user can set or clear the
  3772.         modified flag. If boolean is specified, sets the
  3773.         modified flag of the widget to arg.
  3774.         '''
  3775.         return self.edit('modified', arg)
  3776.  
  3777.     
  3778.     def edit_redo(self):
  3779.         '''Redo the last undone edit
  3780.  
  3781.         When the undo option is true, reapplies the last
  3782.         undone edits provided no other edits were done since
  3783.         then. Generates an error when the redo stack is empty.
  3784.         Does nothing when the undo option is false.
  3785.         '''
  3786.         return self.edit('redo')
  3787.  
  3788.     
  3789.     def edit_reset(self):
  3790.         '''Clears the undo and redo stacks
  3791.         '''
  3792.         return self.edit('reset')
  3793.  
  3794.     
  3795.     def edit_separator(self):
  3796.         '''Inserts a separator (boundary) on the undo stack.
  3797.  
  3798.         Does nothing when the undo option is false
  3799.         '''
  3800.         return self.edit('separator')
  3801.  
  3802.     
  3803.     def edit_undo(self):
  3804.         '''Undoes the last edit action
  3805.  
  3806.         If the undo option is true. An edit action is defined
  3807.         as all the insert and delete commands that are recorded
  3808.         on the undo stack in between two separators. Generates
  3809.         an error when the undo stack is empty. Does nothing
  3810.         when the undo option is false
  3811.         '''
  3812.         return self.edit('undo')
  3813.  
  3814.     
  3815.     def get(self, index1, index2 = None):
  3816.         '''Return the text from INDEX1 to INDEX2 (not included).'''
  3817.         return self.tk.call(self._w, 'get', index1, index2)
  3818.  
  3819.     
  3820.     def image_cget(self, index, option):
  3821.         '''Return the value of OPTION of an embedded image at INDEX.'''
  3822.         if option[:1] != '-':
  3823.             option = '-' + option
  3824.         
  3825.         if option[-1:] == '_':
  3826.             option = option[:-1]
  3827.         
  3828.         return self.tk.call(self._w, 'image', 'cget', index, option)
  3829.  
  3830.     
  3831.     def image_configure(self, index, cnf = None, **kw):
  3832.         '''Configure an embedded image at INDEX.'''
  3833.         return self._configure(('image', 'configure', index), cnf, kw)
  3834.  
  3835.     
  3836.     def image_create(self, index, cnf = { }, **kw):
  3837.         '''Create an embedded image at INDEX.'''
  3838.         return self.tk.call(self._w, 'image', 'create', index, *self._options(cnf, kw))
  3839.  
  3840.     
  3841.     def image_names(self):
  3842.         '''Return all names of embedded images in this widget.'''
  3843.         return self.tk.call(self._w, 'image', 'names')
  3844.  
  3845.     
  3846.     def index(self, index):
  3847.         '''Return the index in the form line.char for INDEX.'''
  3848.         return str(self.tk.call(self._w, 'index', index))
  3849.  
  3850.     
  3851.     def insert(self, index, chars, *args):
  3852.         '''Insert CHARS before the characters at INDEX. An additional
  3853.         tag can be given in ARGS. Additional CHARS and tags can follow in ARGS.'''
  3854.         self.tk.call((self._w, 'insert', index, chars) + args)
  3855.  
  3856.     
  3857.     def mark_gravity(self, markName, direction = None):
  3858.         '''Change the gravity of a mark MARKNAME to DIRECTION (LEFT or RIGHT).
  3859.         Return the current value if None is given for DIRECTION.'''
  3860.         return self.tk.call((self._w, 'mark', 'gravity', markName, direction))
  3861.  
  3862.     
  3863.     def mark_names(self):
  3864.         '''Return all mark names.'''
  3865.         return self.tk.splitlist(self.tk.call(self._w, 'mark', 'names'))
  3866.  
  3867.     
  3868.     def mark_set(self, markName, index):
  3869.         '''Set mark MARKNAME before the character at INDEX.'''
  3870.         self.tk.call(self._w, 'mark', 'set', markName, index)
  3871.  
  3872.     
  3873.     def mark_unset(self, *markNames):
  3874.         '''Delete all marks in MARKNAMES.'''
  3875.         self.tk.call((self._w, 'mark', 'unset') + markNames)
  3876.  
  3877.     
  3878.     def mark_next(self, index):
  3879.         '''Return the name of the next mark after INDEX.'''
  3880.         if not self.tk.call(self._w, 'mark', 'next', index):
  3881.             pass
  3882.  
  3883.     
  3884.     def mark_previous(self, index):
  3885.         '''Return the name of the previous mark before INDEX.'''
  3886.         if not self.tk.call(self._w, 'mark', 'previous', index):
  3887.             pass
  3888.  
  3889.     
  3890.     def scan_mark(self, x, y):
  3891.         '''Remember the current X, Y coordinates.'''
  3892.         self.tk.call(self._w, 'scan', 'mark', x, y)
  3893.  
  3894.     
  3895.     def scan_dragto(self, x, y):
  3896.         '''Adjust the view of the text to 10 times the
  3897.         difference between X and Y and the coordinates given in
  3898.         scan_mark.'''
  3899.         self.tk.call(self._w, 'scan', 'dragto', x, y)
  3900.  
  3901.     
  3902.     def search(self, pattern, index, stopindex = None, forwards = None, backwards = None, exact = None, regexp = None, nocase = None, count = None, elide = None):
  3903.         '''Search PATTERN beginning from INDEX until STOPINDEX.
  3904.         Return the index of the first character of a match or an
  3905.         empty string.'''
  3906.         args = [
  3907.             self._w,
  3908.             'search']
  3909.         if forwards:
  3910.             args.append('-forwards')
  3911.         
  3912.         if backwards:
  3913.             args.append('-backwards')
  3914.         
  3915.         if exact:
  3916.             args.append('-exact')
  3917.         
  3918.         if regexp:
  3919.             args.append('-regexp')
  3920.         
  3921.         if nocase:
  3922.             args.append('-nocase')
  3923.         
  3924.         if elide:
  3925.             args.append('-elide')
  3926.         
  3927.         if count:
  3928.             args.append('-count')
  3929.             args.append(count)
  3930.         
  3931.         if pattern and pattern[0] == '-':
  3932.             args.append('--')
  3933.         
  3934.         args.append(pattern)
  3935.         args.append(index)
  3936.         if stopindex:
  3937.             args.append(stopindex)
  3938.         
  3939.         return str(self.tk.call(tuple(args)))
  3940.  
  3941.     
  3942.     def see(self, index):
  3943.         '''Scroll such that the character at INDEX is visible.'''
  3944.         self.tk.call(self._w, 'see', index)
  3945.  
  3946.     
  3947.     def tag_add(self, tagName, index1, *args):
  3948.         '''Add tag TAGNAME to all characters between INDEX1 and index2 in ARGS.
  3949.         Additional pairs of indices may follow in ARGS.'''
  3950.         self.tk.call((self._w, 'tag', 'add', tagName, index1) + args)
  3951.  
  3952.     
  3953.     def tag_unbind(self, tagName, sequence, funcid = None):
  3954.         '''Unbind for all characters with TAGNAME for event SEQUENCE  the
  3955.         function identified with FUNCID.'''
  3956.         self.tk.call(self._w, 'tag', 'bind', tagName, sequence, '')
  3957.         if funcid:
  3958.             self.deletecommand(funcid)
  3959.         
  3960.  
  3961.     
  3962.     def tag_bind(self, tagName, sequence, func, add = None):
  3963.         '''Bind to all characters with TAGNAME at event SEQUENCE a call to function FUNC.
  3964.  
  3965.         An additional boolean parameter ADD specifies whether FUNC will be
  3966.         called additionally to the other bound function or whether it will
  3967.         replace the previous function. See bind for the return value.'''
  3968.         return self._bind((self._w, 'tag', 'bind', tagName), sequence, func, add)
  3969.  
  3970.     
  3971.     def tag_cget(self, tagName, option):
  3972.         '''Return the value of OPTION for tag TAGNAME.'''
  3973.         if option[:1] != '-':
  3974.             option = '-' + option
  3975.         
  3976.         if option[-1:] == '_':
  3977.             option = option[:-1]
  3978.         
  3979.         return self.tk.call(self._w, 'tag', 'cget', tagName, option)
  3980.  
  3981.     
  3982.     def tag_configure(self, tagName, cnf = None, **kw):
  3983.         '''Configure a tag TAGNAME.'''
  3984.         return self._configure(('tag', 'configure', tagName), cnf, kw)
  3985.  
  3986.     tag_config = tag_configure
  3987.     
  3988.     def tag_delete(self, *tagNames):
  3989.         '''Delete all tags in TAGNAMES.'''
  3990.         self.tk.call((self._w, 'tag', 'delete') + tagNames)
  3991.  
  3992.     
  3993.     def tag_lower(self, tagName, belowThis = None):
  3994.         '''Change the priority of tag TAGNAME such that it is lower
  3995.         than the priority of BELOWTHIS.'''
  3996.         self.tk.call(self._w, 'tag', 'lower', tagName, belowThis)
  3997.  
  3998.     
  3999.     def tag_names(self, index = None):
  4000.         '''Return a list of all tag names.'''
  4001.         return self.tk.splitlist(self.tk.call(self._w, 'tag', 'names', index))
  4002.  
  4003.     
  4004.     def tag_nextrange(self, tagName, index1, index2 = None):
  4005.         '''Return a list of start and end index for the first sequence of
  4006.         characters between INDEX1 and INDEX2 which all have tag TAGNAME.
  4007.         The text is searched forward from INDEX1.'''
  4008.         return self.tk.splitlist(self.tk.call(self._w, 'tag', 'nextrange', tagName, index1, index2))
  4009.  
  4010.     
  4011.     def tag_prevrange(self, tagName, index1, index2 = None):
  4012.         '''Return a list of start and end index for the first sequence of
  4013.         characters between INDEX1 and INDEX2 which all have tag TAGNAME.
  4014.         The text is searched backwards from INDEX1.'''
  4015.         return self.tk.splitlist(self.tk.call(self._w, 'tag', 'prevrange', tagName, index1, index2))
  4016.  
  4017.     
  4018.     def tag_raise(self, tagName, aboveThis = None):
  4019.         '''Change the priority of tag TAGNAME such that it is higher
  4020.         than the priority of ABOVETHIS.'''
  4021.         self.tk.call(self._w, 'tag', 'raise', tagName, aboveThis)
  4022.  
  4023.     
  4024.     def tag_ranges(self, tagName):
  4025.         '''Return a list of ranges of text which have tag TAGNAME.'''
  4026.         return self.tk.splitlist(self.tk.call(self._w, 'tag', 'ranges', tagName))
  4027.  
  4028.     
  4029.     def tag_remove(self, tagName, index1, index2 = None):
  4030.         '''Remove tag TAGNAME from all characters between INDEX1 and INDEX2.'''
  4031.         self.tk.call(self._w, 'tag', 'remove', tagName, index1, index2)
  4032.  
  4033.     
  4034.     def window_cget(self, index, option):
  4035.         '''Return the value of OPTION of an embedded window at INDEX.'''
  4036.         if option[:1] != '-':
  4037.             option = '-' + option
  4038.         
  4039.         if option[-1:] == '_':
  4040.             option = option[:-1]
  4041.         
  4042.         return self.tk.call(self._w, 'window', 'cget', index, option)
  4043.  
  4044.     
  4045.     def window_configure(self, index, cnf = None, **kw):
  4046.         '''Configure an embedded window at INDEX.'''
  4047.         return self._configure(('window', 'configure', index), cnf, kw)
  4048.  
  4049.     window_config = window_configure
  4050.     
  4051.     def window_create(self, index, cnf = { }, **kw):
  4052.         '''Create a window at INDEX.'''
  4053.         self.tk.call((self._w, 'window', 'create', index) + self._options(cnf, kw))
  4054.  
  4055.     
  4056.     def window_names(self):
  4057.         '''Return all names of embedded windows in this widget.'''
  4058.         return self.tk.splitlist(self.tk.call(self._w, 'window', 'names'))
  4059.  
  4060.     
  4061.     def xview(self, *what):
  4062.         '''Query and change horizontal position of the view.'''
  4063.         if not what:
  4064.             return self._getdoubles(self.tk.call(self._w, 'xview'))
  4065.         self.tk.call((self._w, 'xview') + what)
  4066.  
  4067.     
  4068.     def xview_moveto(self, fraction):
  4069.         '''Adjusts the view in the window so that FRACTION of the
  4070.         total width of the canvas is off-screen to the left.'''
  4071.         self.tk.call(self._w, 'xview', 'moveto', fraction)
  4072.  
  4073.     
  4074.     def xview_scroll(self, number, what):
  4075.         '''Shift the x-view according to NUMBER which is measured
  4076.         in "units" or "pages" (WHAT).'''
  4077.         self.tk.call(self._w, 'xview', 'scroll', number, what)
  4078.  
  4079.     
  4080.     def yview(self, *what):
  4081.         '''Query and change vertical position of the view.'''
  4082.         if not what:
  4083.             return self._getdoubles(self.tk.call(self._w, 'yview'))
  4084.         self.tk.call((self._w, 'yview') + what)
  4085.  
  4086.     
  4087.     def yview_moveto(self, fraction):
  4088.         '''Adjusts the view in the window so that FRACTION of the
  4089.         total height of the canvas is off-screen to the top.'''
  4090.         self.tk.call(self._w, 'yview', 'moveto', fraction)
  4091.  
  4092.     
  4093.     def yview_scroll(self, number, what):
  4094.         '''Shift the y-view according to NUMBER which is measured
  4095.         in "units" or "pages" (WHAT).'''
  4096.         self.tk.call(self._w, 'yview', 'scroll', number, what)
  4097.  
  4098.     
  4099.     def yview_pickplace(self, *what):
  4100.         '''Obsolete function, use see.'''
  4101.         self.tk.call((self._w, 'yview', '-pickplace') + what)
  4102.  
  4103.  
  4104.  
  4105. class _setit:
  4106.     '''Internal class. It wraps the command in the widget OptionMenu.'''
  4107.     
  4108.     def __init__(self, var, value, callback = None):
  4109.         self._setit__value = value
  4110.         self._setit__var = var
  4111.         self._setit__callback = callback
  4112.  
  4113.     
  4114.     def __call__(self, *args):
  4115.         self._setit__var.set(self._setit__value)
  4116.         if self._setit__callback:
  4117.             self._setit__callback(self._setit__value, *args)
  4118.         
  4119.  
  4120.  
  4121.  
  4122. class OptionMenu(Menubutton):
  4123.     '''OptionMenu which allows the user to select a value from a menu.'''
  4124.     
  4125.     def __init__(self, master, variable, value, *values, **kwargs):
  4126.         '''Construct an optionmenu widget with the parent MASTER, with
  4127.         the resource textvariable set to VARIABLE, the initially selected
  4128.         value VALUE, the other menu values VALUES and an additional
  4129.         keyword argument command.'''
  4130.         kw = {
  4131.             'borderwidth': 2,
  4132.             'textvariable': variable,
  4133.             'indicatoron': 1,
  4134.             'relief': RAISED,
  4135.             'anchor': 'c',
  4136.             'highlightthickness': 2 }
  4137.         Widget.__init__(self, master, 'menubutton', kw)
  4138.         self.widgetName = 'tk_optionMenu'
  4139.         menu = self._OptionMenu__menu = Menu(self, name = 'menu', tearoff = 0)
  4140.         self.menuname = menu._w
  4141.         callback = kwargs.get('command')
  4142.         if kwargs.has_key('command'):
  4143.             del kwargs['command']
  4144.         
  4145.         if kwargs:
  4146.             raise TclError, 'unknown option -' + kwargs.keys()[0]
  4147.         kwargs
  4148.         menu.add_command(label = value, command = _setit(variable, value, callback))
  4149.         for v in values:
  4150.             menu.add_command(label = v, command = _setit(variable, v, callback))
  4151.         
  4152.         self['menu'] = menu
  4153.  
  4154.     
  4155.     def __getitem__(self, name):
  4156.         if name == 'menu':
  4157.             return self._OptionMenu__menu
  4158.         return Widget.__getitem__(self, name)
  4159.  
  4160.     
  4161.     def destroy(self):
  4162.         '''Destroy this widget and the associated menu.'''
  4163.         Menubutton.destroy(self)
  4164.         self._OptionMenu__menu = None
  4165.  
  4166.  
  4167.  
  4168. class Image:
  4169.     '''Base class for images.'''
  4170.     _last_id = 0
  4171.     
  4172.     def __init__(self, imgtype, name = None, cnf = { }, master = None, **kw):
  4173.         self.name = None
  4174.         if not master:
  4175.             master = _default_root
  4176.             if not master:
  4177.                 raise RuntimeError, 'Too early to create image'
  4178.             master
  4179.         
  4180.         self.tk = master.tk
  4181.         if not name:
  4182.             Image._last_id += 1
  4183.             name = 'pyimage%r' % (Image._last_id,)
  4184.             if name[0] == '-':
  4185.                 name = '_' + name[1:]
  4186.             
  4187.         
  4188.         if kw and cnf:
  4189.             cnf = _cnfmerge((cnf, kw))
  4190.         elif kw:
  4191.             cnf = kw
  4192.         
  4193.         options = ()
  4194.         for k, v in cnf.items():
  4195.             if callable(v):
  4196.                 v = self._register(v)
  4197.             
  4198.             options = options + ('-' + k, v)
  4199.         
  4200.         self.tk.call(('image', 'create', imgtype, name) + options)
  4201.         self.name = name
  4202.  
  4203.     
  4204.     def __str__(self):
  4205.         return self.name
  4206.  
  4207.     
  4208.     def __del__(self):
  4209.         if self.name:
  4210.             
  4211.             try:
  4212.                 self.tk.call('image', 'delete', self.name)
  4213.             except TclError:
  4214.                 pass
  4215.             except:
  4216.                 None<EXCEPTION MATCH>TclError
  4217.             
  4218.  
  4219.         None<EXCEPTION MATCH>TclError
  4220.  
  4221.     
  4222.     def __setitem__(self, key, value):
  4223.         self.tk.call(self.name, 'configure', '-' + key, value)
  4224.  
  4225.     
  4226.     def __getitem__(self, key):
  4227.         return self.tk.call(self.name, 'configure', '-' + key)
  4228.  
  4229.     
  4230.     def configure(self, **kw):
  4231.         '''Configure the image.'''
  4232.         res = ()
  4233.         for k, v in _cnfmerge(kw).items():
  4234.             if v is not None:
  4235.                 if k[-1] == '_':
  4236.                     k = k[:-1]
  4237.                 
  4238.                 if callable(v):
  4239.                     v = self._register(v)
  4240.                 
  4241.                 res = res + ('-' + k, v)
  4242.                 continue
  4243.         
  4244.         self.tk.call((self.name, 'config') + res)
  4245.  
  4246.     config = configure
  4247.     
  4248.     def height(self):
  4249.         '''Return the height of the image.'''
  4250.         return getint(self.tk.call('image', 'height', self.name))
  4251.  
  4252.     
  4253.     def type(self):
  4254.         '''Return the type of the imgage, e.g. "photo" or "bitmap".'''
  4255.         return self.tk.call('image', 'type', self.name)
  4256.  
  4257.     
  4258.     def width(self):
  4259.         '''Return the width of the image.'''
  4260.         return getint(self.tk.call('image', 'width', self.name))
  4261.  
  4262.  
  4263.  
  4264. class PhotoImage(Image):
  4265.     '''Widget which can display colored images in GIF, PPM/PGM format.'''
  4266.     
  4267.     def __init__(self, name = None, cnf = { }, master = None, **kw):
  4268.         '''Create an image with NAME.
  4269.  
  4270.         Valid resource names: data, format, file, gamma, height, palette,
  4271.         width.'''
  4272.         Image.__init__(self, 'photo', name, cnf, master, **kw)
  4273.  
  4274.     
  4275.     def blank(self):
  4276.         '''Display a transparent image.'''
  4277.         self.tk.call(self.name, 'blank')
  4278.  
  4279.     
  4280.     def cget(self, option):
  4281.         '''Return the value of OPTION.'''
  4282.         return self.tk.call(self.name, 'cget', '-' + option)
  4283.  
  4284.     
  4285.     def __getitem__(self, key):
  4286.         return self.tk.call(self.name, 'cget', '-' + key)
  4287.  
  4288.     
  4289.     def copy(self):
  4290.         '''Return a new PhotoImage with the same image as this widget.'''
  4291.         destImage = PhotoImage()
  4292.         self.tk.call(destImage, 'copy', self.name)
  4293.         return destImage
  4294.  
  4295.     
  4296.     def zoom(self, x, y = ''):
  4297.         '''Return a new PhotoImage with the same image as this widget
  4298.         but zoom it with X and Y.'''
  4299.         destImage = PhotoImage()
  4300.         if y == '':
  4301.             y = x
  4302.         
  4303.         self.tk.call(destImage, 'copy', self.name, '-zoom', x, y)
  4304.         return destImage
  4305.  
  4306.     
  4307.     def subsample(self, x, y = ''):
  4308.         '''Return a new PhotoImage based on the same image as this widget
  4309.         but use only every Xth or Yth pixel.'''
  4310.         destImage = PhotoImage()
  4311.         if y == '':
  4312.             y = x
  4313.         
  4314.         self.tk.call(destImage, 'copy', self.name, '-subsample', x, y)
  4315.         return destImage
  4316.  
  4317.     
  4318.     def get(self, x, y):
  4319.         '''Return the color (red, green, blue) of the pixel at X,Y.'''
  4320.         return self.tk.call(self.name, 'get', x, y)
  4321.  
  4322.     
  4323.     def put(self, data, to = None):
  4324.         '''Put row formatted colors to image starting from
  4325.         position TO, e.g. image.put("{red green} {blue yellow}", to=(4,6))'''
  4326.         args = (self.name, 'put', data)
  4327.         if to:
  4328.             if to[0] == '-to':
  4329.                 to = to[1:]
  4330.             
  4331.             args = args + ('-to',) + tuple(to)
  4332.         
  4333.         self.tk.call(args)
  4334.  
  4335.     
  4336.     def write(self, filename, format = None, from_coords = None):
  4337.         '''Write image to file FILENAME in FORMAT starting from
  4338.         position FROM_COORDS.'''
  4339.         args = (self.name, 'write', filename)
  4340.         if format:
  4341.             args = args + ('-format', format)
  4342.         
  4343.         if from_coords:
  4344.             args = args + ('-from',) + tuple(from_coords)
  4345.         
  4346.         self.tk.call(args)
  4347.  
  4348.  
  4349.  
  4350. class BitmapImage(Image):
  4351.     '''Widget which can display a bitmap.'''
  4352.     
  4353.     def __init__(self, name = None, cnf = { }, master = None, **kw):
  4354.         '''Create a bitmap with NAME.
  4355.  
  4356.         Valid resource names: background, data, file, foreground, maskdata, maskfile.'''
  4357.         Image.__init__(self, 'bitmap', name, cnf, master, **kw)
  4358.  
  4359.  
  4360.  
  4361. def image_names():
  4362.     return _default_root.tk.call('image', 'names')
  4363.  
  4364.  
  4365. def image_types():
  4366.     return _default_root.tk.call('image', 'types')
  4367.  
  4368.  
  4369. class Spinbox(Widget):
  4370.     '''spinbox widget.'''
  4371.     
  4372.     def __init__(self, master = None, cnf = { }, **kw):
  4373.         '''Construct a spinbox widget with the parent MASTER.
  4374.  
  4375.         STANDARD OPTIONS
  4376.  
  4377.             activebackground, background, borderwidth,
  4378.             cursor, exportselection, font, foreground,
  4379.             highlightbackground, highlightcolor,
  4380.             highlightthickness, insertbackground,
  4381.             insertborderwidth, insertofftime,
  4382.             insertontime, insertwidth, justify, relief,
  4383.             repeatdelay, repeatinterval,
  4384.             selectbackground, selectborderwidth
  4385.             selectforeground, takefocus, textvariable
  4386.             xscrollcommand.
  4387.  
  4388.         WIDGET-SPECIFIC OPTIONS
  4389.  
  4390.             buttonbackground, buttoncursor,
  4391.             buttondownrelief, buttonuprelief,
  4392.             command, disabledbackground,
  4393.             disabledforeground, format, from,
  4394.             invalidcommand, increment,
  4395.             readonlybackground, state, to,
  4396.             validate, validatecommand values,
  4397.             width, wrap,
  4398.         '''
  4399.         Widget.__init__(self, master, 'spinbox', cnf, kw)
  4400.  
  4401.     
  4402.     def bbox(self, index):
  4403.         '''Return a tuple of X1,Y1,X2,Y2 coordinates for a
  4404.         rectangle which encloses the character given by index.
  4405.  
  4406.         The first two elements of the list give the x and y
  4407.         coordinates of the upper-left corner of the screen
  4408.         area covered by the character (in pixels relative
  4409.         to the widget) and the last two elements give the
  4410.         width and height of the character, in pixels. The
  4411.         bounding box may refer to a region outside the
  4412.         visible area of the window.
  4413.         '''
  4414.         return self.tk.call(self._w, 'bbox', index)
  4415.  
  4416.     
  4417.     def delete(self, first, last = None):
  4418.         """Delete one or more elements of the spinbox.
  4419.  
  4420.         First is the index of the first character to delete,
  4421.         and last is the index of the character just after
  4422.         the last one to delete. If last isn't specified it
  4423.         defaults to first+1, i.e. a single character is
  4424.         deleted.  This command returns an empty string.
  4425.         """
  4426.         return self.tk.call(self._w, 'delete', first, last)
  4427.  
  4428.     
  4429.     def get(self):
  4430.         """Returns the spinbox's string"""
  4431.         return self.tk.call(self._w, 'get')
  4432.  
  4433.     
  4434.     def icursor(self, index):
  4435.         '''Alter the position of the insertion cursor.
  4436.  
  4437.         The insertion cursor will be displayed just before
  4438.         the character given by index. Returns an empty string
  4439.         '''
  4440.         return self.tk.call(self._w, 'icursor', index)
  4441.  
  4442.     
  4443.     def identify(self, x, y):
  4444.         '''Returns the name of the widget at position x, y
  4445.  
  4446.         Return value is one of: none, buttondown, buttonup, entry
  4447.         '''
  4448.         return self.tk.call(self._w, 'identify', x, y)
  4449.  
  4450.     
  4451.     def index(self, index):
  4452.         '''Returns the numerical index corresponding to index
  4453.         '''
  4454.         return self.tk.call(self._w, 'index', index)
  4455.  
  4456.     
  4457.     def insert(self, index, s):
  4458.         '''Insert string s at index
  4459.  
  4460.          Returns an empty string.
  4461.         '''
  4462.         return self.tk.call(self._w, 'insert', index, s)
  4463.  
  4464.     
  4465.     def invoke(self, element):
  4466.         '''Causes the specified element to be invoked
  4467.  
  4468.         The element could be buttondown or buttonup
  4469.         triggering the action associated with it.
  4470.         '''
  4471.         return self.tk.call(self._w, 'invoke', element)
  4472.  
  4473.     
  4474.     def scan(self, *args):
  4475.         '''Internal function.'''
  4476.         if not self._getints(self.tk.call((self._w, 'scan') + args)):
  4477.             pass
  4478.         return ()
  4479.  
  4480.     
  4481.     def scan_mark(self, x):
  4482.         '''Records x and the current view in the spinbox window;
  4483.  
  4484.         used in conjunction with later scan dragto commands.
  4485.         Typically this command is associated with a mouse button
  4486.         press in the widget. It returns an empty string.
  4487.         '''
  4488.         return self.scan('mark', x)
  4489.  
  4490.     
  4491.     def scan_dragto(self, x):
  4492.         '''Compute the difference between the given x argument
  4493.         and the x argument to the last scan mark command
  4494.  
  4495.         It then adjusts the view left or right by 10 times the
  4496.         difference in x-coordinates. This command is typically
  4497.         associated with mouse motion events in the widget, to
  4498.         produce the effect of dragging the spinbox at high speed
  4499.         through the window. The return value is an empty string.
  4500.         '''
  4501.         return self.scan('dragto', x)
  4502.  
  4503.     
  4504.     def selection(self, *args):
  4505.         '''Internal function.'''
  4506.         if not self._getints(self.tk.call((self._w, 'selection') + args)):
  4507.             pass
  4508.         return ()
  4509.  
  4510.     
  4511.     def selection_adjust(self, index):
  4512.         """Locate the end of the selection nearest to the character
  4513.         given by index,
  4514.  
  4515.         Then adjust that end of the selection to be at index
  4516.         (i.e including but not going beyond index). The other
  4517.         end of the selection is made the anchor point for future
  4518.         select to commands. If the selection isn't currently in
  4519.         the spinbox, then a new selection is created to include
  4520.         the characters between index and the most recent selection
  4521.         anchor point, inclusive. Returns an empty string.
  4522.         """
  4523.         return self.selection('adjust', index)
  4524.  
  4525.     
  4526.     def selection_clear(self):
  4527.         """Clear the selection
  4528.  
  4529.         If the selection isn't in this widget then the
  4530.         command has no effect. Returns an empty string.
  4531.         """
  4532.         return self.selection('clear')
  4533.  
  4534.     
  4535.     def selection_element(self, element = None):
  4536.         '''Sets or gets the currently selected element.
  4537.  
  4538.         If a spinbutton element is specified, it will be
  4539.         displayed depressed
  4540.         '''
  4541.         return self.selection('element', element)
  4542.  
  4543.  
  4544.  
  4545. class LabelFrame(Widget):
  4546.     '''labelframe widget.'''
  4547.     
  4548.     def __init__(self, master = None, cnf = { }, **kw):
  4549.         '''Construct a labelframe widget with the parent MASTER.
  4550.  
  4551.         STANDARD OPTIONS
  4552.  
  4553.             borderwidth, cursor, font, foreground,
  4554.             highlightbackground, highlightcolor,
  4555.             highlightthickness, padx, pady, relief,
  4556.             takefocus, text
  4557.  
  4558.         WIDGET-SPECIFIC OPTIONS
  4559.  
  4560.             background, class, colormap, container,
  4561.             height, labelanchor, labelwidget,
  4562.             visual, width
  4563.         '''
  4564.         Widget.__init__(self, master, 'labelframe', cnf, kw)
  4565.  
  4566.  
  4567.  
  4568. class PanedWindow(Widget):
  4569.     '''panedwindow widget.'''
  4570.     
  4571.     def __init__(self, master = None, cnf = { }, **kw):
  4572.         '''Construct a panedwindow widget with the parent MASTER.
  4573.  
  4574.         STANDARD OPTIONS
  4575.  
  4576.             background, borderwidth, cursor, height,
  4577.             orient, relief, width
  4578.  
  4579.         WIDGET-SPECIFIC OPTIONS
  4580.  
  4581.             handlepad, handlesize, opaqueresize,
  4582.             sashcursor, sashpad, sashrelief,
  4583.             sashwidth, showhandle,
  4584.         '''
  4585.         Widget.__init__(self, master, 'panedwindow', cnf, kw)
  4586.  
  4587.     
  4588.     def add(self, child, **kw):
  4589.         '''Add a child widget to the panedwindow in a new pane.
  4590.  
  4591.         The child argument is the name of the child widget
  4592.         followed by pairs of arguments that specify how to
  4593.         manage the windows. Options may have any of the values
  4594.         accepted by the configure subcommand.
  4595.         '''
  4596.         self.tk.call((self._w, 'add', child) + self._options(kw))
  4597.  
  4598.     
  4599.     def remove(self, child):
  4600.         '''Remove the pane containing child from the panedwindow
  4601.  
  4602.         All geometry management options for child will be forgotten.
  4603.         '''
  4604.         self.tk.call(self._w, 'forget', child)
  4605.  
  4606.     forget = remove
  4607.     
  4608.     def identify(self, x, y):
  4609.         '''Identify the panedwindow component at point x, y
  4610.  
  4611.         If the point is over a sash or a sash handle, the result
  4612.         is a two element list containing the index of the sash or
  4613.         handle, and a word indicating whether it is over a sash
  4614.         or a handle, such as {0 sash} or {2 handle}. If the point
  4615.         is over any other part of the panedwindow, the result is
  4616.         an empty list.
  4617.         '''
  4618.         return self.tk.call(self._w, 'identify', x, y)
  4619.  
  4620.     
  4621.     def proxy(self, *args):
  4622.         '''Internal function.'''
  4623.         if not self._getints(self.tk.call((self._w, 'proxy') + args)):
  4624.             pass
  4625.         return ()
  4626.  
  4627.     
  4628.     def proxy_coord(self):
  4629.         '''Return the x and y pair of the most recent proxy location
  4630.         '''
  4631.         return self.proxy('coord')
  4632.  
  4633.     
  4634.     def proxy_forget(self):
  4635.         '''Remove the proxy from the display.
  4636.         '''
  4637.         return self.proxy('forget')
  4638.  
  4639.     
  4640.     def proxy_place(self, x, y):
  4641.         '''Place the proxy at the given x and y coordinates.
  4642.         '''
  4643.         return self.proxy('place', x, y)
  4644.  
  4645.     
  4646.     def sash(self, *args):
  4647.         '''Internal function.'''
  4648.         if not self._getints(self.tk.call((self._w, 'sash') + args)):
  4649.             pass
  4650.         return ()
  4651.  
  4652.     
  4653.     def sash_coord(self, index):
  4654.         '''Return the current x and y pair for the sash given by index.
  4655.  
  4656.         Index must be an integer between 0 and 1 less than the
  4657.         number of panes in the panedwindow. The coordinates given are
  4658.         those of the top left corner of the region containing the sash.
  4659.         pathName sash dragto index x y This command computes the
  4660.         difference between the given coordinates and the coordinates
  4661.         given to the last sash coord command for the given sash. It then
  4662.         moves that sash the computed difference. The return value is the
  4663.         empty string.
  4664.         '''
  4665.         return self.sash('coord', index)
  4666.  
  4667.     
  4668.     def sash_mark(self, index):
  4669.         '''Records x and y for the sash given by index;
  4670.  
  4671.         Used in conjunction with later dragto commands to move the sash.
  4672.         '''
  4673.         return self.sash('mark', index)
  4674.  
  4675.     
  4676.     def sash_place(self, index, x, y):
  4677.         '''Place the sash given by index at the given coordinates
  4678.         '''
  4679.         return self.sash('place', index, x, y)
  4680.  
  4681.     
  4682.     def panecget(self, child, option):
  4683.         '''Query a management option for window.
  4684.  
  4685.         Option may be any value allowed by the paneconfigure subcommand
  4686.         '''
  4687.         return self.tk.call((self._w, 'panecget') + (child, '-' + option))
  4688.  
  4689.     
  4690.     def paneconfigure(self, tagOrId, cnf = None, **kw):
  4691.         '''Query or modify the management options for window.
  4692.  
  4693.         If no option is specified, returns a list describing all
  4694.         of the available options for pathName.  If option is
  4695.         specified with no value, then the command returns a list
  4696.         describing the one named option (this list will be identical
  4697.         to the corresponding sublist of the value returned if no
  4698.         option is specified). If one or more option-value pairs are
  4699.         specified, then the command modifies the given widget
  4700.         option(s) to have the given value(s); in this case the
  4701.         command returns an empty string. The following options
  4702.         are supported:
  4703.  
  4704.         after window
  4705.             Insert the window after the window specified. window
  4706.             should be the name of a window already managed by pathName.
  4707.         before window
  4708.             Insert the window before the window specified. window
  4709.             should be the name of a window already managed by pathName.
  4710.         height size
  4711.             Specify a height for the window. The height will be the
  4712.             outer dimension of the window including its border, if
  4713.             any. If size is an empty string, or if -height is not
  4714.             specified, then the height requested internally by the
  4715.             window will be used initially; the height may later be
  4716.             adjusted by the movement of sashes in the panedwindow.
  4717.             Size may be any value accepted by Tk_GetPixels.
  4718.         minsize n
  4719.             Specifies that the size of the window cannot be made
  4720.             less than n. This constraint only affects the size of
  4721.             the widget in the paned dimension -- the x dimension
  4722.             for horizontal panedwindows, the y dimension for
  4723.             vertical panedwindows. May be any value accepted by
  4724.             Tk_GetPixels.
  4725.         padx n
  4726.             Specifies a non-negative value indicating how much
  4727.             extra space to leave on each side of the window in
  4728.             the X-direction. The value may have any of the forms
  4729.             accepted by Tk_GetPixels.
  4730.         pady n
  4731.             Specifies a non-negative value indicating how much
  4732.             extra space to leave on each side of the window in
  4733.             the Y-direction. The value may have any of the forms
  4734.             accepted by Tk_GetPixels.
  4735.         sticky style
  4736.             If a window\'s pane is larger than the requested
  4737.             dimensions of the window, this option may be used
  4738.             to position (or stretch) the window within its pane.
  4739.             Style is a string that contains zero or more of the
  4740.             characters n, s, e or w. The string can optionally
  4741.             contains spaces or commas, but they are ignored. Each
  4742.             letter refers to a side (north, south, east, or west)
  4743.             that the window will "stick" to. If both n and s
  4744.             (or e and w) are specified, the window will be
  4745.             stretched to fill the entire height (or width) of
  4746.             its cavity.
  4747.         width size
  4748.             Specify a width for the window. The width will be
  4749.             the outer dimension of the window including its
  4750.             border, if any. If size is an empty string, or
  4751.             if -width is not specified, then the width requested
  4752.             internally by the window will be used initially; the
  4753.             width may later be adjusted by the movement of sashes
  4754.             in the panedwindow. Size may be any value accepted by
  4755.             Tk_GetPixels.
  4756.  
  4757.         '''
  4758.         if cnf is None and not kw:
  4759.             cnf = { }
  4760.             for x in self.tk.split(self.tk.call(self._w, 'paneconfigure', tagOrId)):
  4761.                 cnf[x[0][1:]] = (x[0][1:],) + x[1:]
  4762.             
  4763.             return cnf
  4764.         if type(cnf) == StringType and not kw:
  4765.             x = self.tk.split(self.tk.call(self._w, 'paneconfigure', tagOrId, '-' + cnf))
  4766.             return (x[0][1:],) + x[1:]
  4767.         self.tk.call((self._w, 'paneconfigure', tagOrId) + self._options(cnf, kw))
  4768.  
  4769.     paneconfig = paneconfigure
  4770.     
  4771.     def panes(self):
  4772.         '''Returns an ordered list of the child panes.'''
  4773.         return self.tk.call(self._w, 'panes')
  4774.  
  4775.  
  4776.  
  4777. class Studbutton(Button):
  4778.     
  4779.     def __init__(self, master = None, cnf = { }, **kw):
  4780.         Widget.__init__(self, master, 'studbutton', cnf, kw)
  4781.         self.bind('<Any-Enter>', self.tkButtonEnter)
  4782.         self.bind('<Any-Leave>', self.tkButtonLeave)
  4783.         self.bind('<1>', self.tkButtonDown)
  4784.         self.bind('<ButtonRelease-1>', self.tkButtonUp)
  4785.  
  4786.  
  4787.  
  4788. class Tributton(Button):
  4789.     
  4790.     def __init__(self, master = None, cnf = { }, **kw):
  4791.         Widget.__init__(self, master, 'tributton', cnf, kw)
  4792.         self.bind('<Any-Enter>', self.tkButtonEnter)
  4793.         self.bind('<Any-Leave>', self.tkButtonLeave)
  4794.         self.bind('<1>', self.tkButtonDown)
  4795.         self.bind('<ButtonRelease-1>', self.tkButtonUp)
  4796.         self['fg'] = self['bg']
  4797.         self['activebackground'] = self['bg']
  4798.  
  4799.  
  4800.  
  4801. def _test():
  4802.     root = Tk()
  4803.     text = 'This is Tcl/Tk version %s' % TclVersion
  4804.     if TclVersion >= 8.1:
  4805.         
  4806.         try:
  4807.             text = text + unicode('\nThis should be a cedilla: \xe7', 'iso-8859-1')
  4808.         except NameError:
  4809.             pass
  4810.         except:
  4811.             None<EXCEPTION MATCH>NameError
  4812.         
  4813.  
  4814.     None<EXCEPTION MATCH>NameError
  4815.     label = Label(root, text = text)
  4816.     label.pack()
  4817.     test = Button(root, text = 'Click me!', command = (lambda root = root: root.test.configure(text = '[%s]' % root.test['text'])))
  4818.     test.pack()
  4819.     root.test = test
  4820.     quit = Button(root, text = 'QUIT', command = root.destroy)
  4821.     quit.pack()
  4822.     root.iconify()
  4823.     root.update()
  4824.     root.deiconify()
  4825.     root.mainloop()
  4826.  
  4827. if __name__ == '__main__':
  4828.     _test()
  4829.  
  4830.